Im trying to develop an app that checks your device's security, and im working on a feature that checks if the pattern is visible (In the lock screen, if u have a pattern and it shows on the screen).
Some versions ago, you could check this in Settings.Secure with:
Settings.Secure.getInt(contentResolver, Settings.Secure.LOCK_PATTERN_VISIBLE)
They changed it and now it is on a class called LockPatternUtils, and the method is called isVisiblePatternEnabled.
The only way to access this class is through reflection, but when I do it, it throws InvocationTargetException caused by NullPointerException.
I tried to debug but got "source code does not match byte code", so I checked the source code in Android Code Search, and it throws NullPointerException cause inside this method, they use ServiceManager.getService("lock_settings"), and that specific part of code returns null.
It says that getService returns "a reference to the service, or null if the service doesn't exist".
The thing is that this service DOES exist, as when I execute the adb command to check a list of services that are running on the emulator, it appears.
So, here is my question: Is there anything that I'm missing?
I know this is a very old query, but I hope this helps.
Even with reflection, only system apps are allowed to get the 'lock_settings' service. This makes sense as these are secure features.
Related
Our game in production environment uses getApkContentsSigners to get apk's signatures regardless of calling hasMultipleSigners, and I want to know what will happen in this wrong case.
(So far we haven't found any problems)
_______________________
in this document Android SigningInfo
It says
"This method(getApkContentsSigners()) should not be used unless hasMultipleSigners() returns true, indicating that getSigningCertificateHistory() cannot be used, otherwise getSigningCertificateHistory() should be preferred."
But in my previous app release, we use getApkContentsSigners() directly with no multiple signers and find no issue so far.
I wonder what exactly happends when I do it in this inappropriate method.
I'm building some general testing tool for Android apps and trying to get the activity name (e.g. com.android.calculator/.Calculator, the com.android.calculator can be obtained through UiDevice.currentPackageName, the pain is from the second part) during the testing. This is to say that my tool may test other apps that are not in the same package as mine. For example, testing the stock calculator app.
Here is a list of attempts I have made:
the UiDevice.currentActivityName is deprecated and it does not provide the accurate information
InstrumentationRegistry.getInstrumentation().targetContext.getSystemService<ActivityManager>(), then access the ActivityManager.getRunningTasks(1).get(0).topActivity, which always returns the same value even though the view has switched (and this is deprecated too)
Similar to 2, I tried ActivityManager.getAppTasks().get(0).getTaskInfo().topActivity, but this keeps giving me null
ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED). This gives me an empty collection
Application.ActivityLifecycleCallbacks. I registered it with the application, but no callback is received.
(Kinda works, but not perfect) using adb dumpsys activity then find it there. But this way I have to wait for some arbitrary time until the view is updated, otherwise the result is still inaccurate
So I am currently in a cul-de-sac now, and I appreciate any help on this issue. I try to avoid reflection, because as I know it does not work on newer devices. So any clue will be appreciated.
As there is no answer posted, I wanna share my current strategy, which is not perfect, but somewhat helpful.
So first of all, as UiDevice.getActivityName is deprecated, I can only obtain the activity name through adb. Specifically, I use adb shell dumpsys activity top for API lower than 28 and adb shell dumpsys activity activities otherwise.
Then I subscribed to AccessibilityEventListener callbacks. Specifically, I run the adb command whenever I receive callbacks with type AccessibilityEvent.TYPE_WINDOWS_CHANGED. You can set up AccessibilityEventListener using this method: setOnAccessibilityEventListener
Assumptions
I have an application with a very large number of screens.
I see the application for the first time so I don't know it
I have a method that connects to the Web Service and I don't know if it is actually used.
Is there any way to check (without running the application) whether the method is actually used in the application?
In Android Studio, you can easily find if a method is used or not.
Right click on the method > "Find usage"
Put a breakpoint on method and start debugging to know whether control
transfers to that method.
Put Log statements inside method to know whether they are executed.
Not recommended: Use Toast messages.
If I understand you, you're looking for "dead code", right ?
You can use Android Lint then: Analyze > Inspect Code...
In the results, Java part I think, you will find Declaration redundancy which will point you the dead code of the project (or the analyzed package)
I am trying to debug a Nativescript app for Android and I have noticed that it no longer prints Syntax errors with their corresponding line and col. numbers, not even console.log statements. How can I enable this feature again? The command I use to launch the app is tns run android. I am using Nativescript version 2.5.2. The VSCode plugin doesn't work either as it ignores any breakpoint I place, and also the console doesn't show any errors. What can I do?
Edit:
It appears that only console.error() statements get printed.
After tinkering a lot with different kinds of constructions and by researching more into how Nativescript relates to regular browser JS, I found out that the problem lies in the use of Promises, which in case of errors defer the execution to the catch() method, but unlike any other regular programming language, "unhandled" rejected results within promises won't raise any kind of exception; which means that, basically, for any promise you invoke in your code, you should have a chained catch() method call so you effectively catch any errors your promises might produce. This also applies to promises which involve navigation, where stuff gets a lot trickier: You might think the next view (say, view.js) will have a call stack on its own and produce an unhandled exception at code that's not even inside a promise in there, but that's not the case: An exception produced at view.js will get captured by the catch() method of the promise within which you started the navigation, and any subsequent promises must have their own catch() method calls because errors won't get bubbled up to the previous view. I can think of many other troublesome constructions but I hope the important bit stays clear: always chain a catch call on any and all promises.
I have a multi-Threaded android application. One of the things my application does is saves various data to a database on a server via webservices. I was trying to figure out why things were not saving to the server correctly, and saw in one of my log files, that the application objects onCreate() method and constructor were called in the middle of one of the requests going up to the server. These request are in the background and are sent via an intentservice.
I have my application set to catch unhandled exceptions and log them, and I did not see anthing in there. The application onCreate() and constructor was called, the application was kicked back to the main/first screen, the user then had to re-login, and it seems that the database was wiped(which is something else I am wondering about).
So, my main questions are: Why did the application object onCreate() and Constructor get called(why did the application get killed), why did the database get wiped when the above happened because if I do a force stop from inside of settings, applications, it never kills my db.
two words: low memory
I have the same problem. No solution for now. Try to take advantage of the onLowMemory() method, maybe the OS will spare your app.
My application object gets restarted randomly (not any time) when I am coming back from an external application (ex. camera or gallery) for onActivityResult().
Hope that helps someone.
If the application is not a service, but a 'normal' application that calles your intentservice, it is subject to the normal application lifecycle: this means it will get killed when in the background.
Look for the explaining image on this site: http://developer.android.com/guide/topics/fundamentals/activities.html
Take note of the red "Process is killed" part on the left, an the subsequent "onCreate()" afterwards.
I've actually seen very similar behaviour that was caused by a NumberFormater trying to parse a null String. After the call to parse(), the application simply reset itself back to the splash screen with no errors at all. Wasn't fun to track down, pretty much stepped through half the code base trying to find out what was happening - the debugger disconnected and the app restarted when stepping past the parse call.