SecurityException when calling BluetoothAdapter.getDefaultAdapter - android

In onCreate() of my app I call BluetoothAdapter.getAddress(). One single device of hundreds, that are running this app, yields a java.lang.SecurityException:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{xx.yyy.myapp/xx.yyy.myapp.RecActivity}:
java.lang.SecurityException: Need BLUETOOTH ADMIN permission: Neither
user 10095 nor current process has android.permission.BLUETOOTH_ADMIN.
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:137) at
android.app.ActivityThread.main(ActivityThread.java:5039) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:511) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at
dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.SecurityException: Need BLUETOOTH ADMIN permission: Neither
user 10095 nor current process has android.permission.BLUETOOTH_ADMIN.
at android.os.Parcel.readException(Parcel.java:1425) at
android.os.Parcel.readException(Parcel.java:1379) at
android.bluetooth.IBluetoothManager$Stub$Proxy.getAddress(IBluetoothManager.java:295)
at
android.bluetooth.BluetoothAdapter.getAddress(BluetoothAdapter.java:576)
at xx.yyy.myapp.RecActivity.onCreate(Unknown Source) at
android.app.Activity.performCreate(Activity.java:5104) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more
As I can't debug on that device I would like to ask if the following solution is feasible or if there's a better way to handle the problem (this is the branch for less than JELLY_BEAN_MR2)?
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
try {
macAddress = ( bta != null ) ? bta.getAddress() : "";
} catch ( Exception e ) {
macAddress = "";
}
Also, I wonder if the Android version on that device might have a bug as it seems to me that getAddress() in BluetoothAdapter.java doesn't require android.permission.BLUETOOTH_ADMIN?
Or is it possible that the user with this device has a specific root tool to lock bluetooth access from my app? And that this might be the reason for the Exception?
Or what might be the reason for the problem?

Since it's bad practice to use catch(Exception e), use
} catch(SecurityException e){
to prevent the crash.
(As an answer now instead of a comment.)

Related

What is the cause of an IllegalArgumentException at onRestoreInstanceState

There was multiple (more than 10) crashes reported in my Google Play Console with this stack trace (full):
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method:0)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method:0)
Caused by: java.lang.IllegalArgumentException:
at android.view.View.onRestoreInstanceState(View.java:12308)
at android.view.View.dispatchRestoreInstanceState(View.java:12284)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2617)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2623)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2623)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2623)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2623)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2623)
at android.view.View.restoreHierarchyState(View.java:12262)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1647)
at android.app.Activity.onRestoreInstanceState(Activity.java:938)
at android.app.Activity.performRestoreInstanceState(Activity.java:910)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1138)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2189)
What would trigger this exception? There was no mention of my application's classes in the stack trace. What should I do?
The following text is written in the Android source code in View.java:12308 as the IllegalArgumentException message:
Wrong state class, expecting View State but received (something else) instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is (view id). Make sure other views do not use the same id.

Security Exception with AccountManager

I'd like to create an account in my Android app programatically.
I've read thing about the AccountManager class and tried to implement it.
Unfortunately, I get a SecurityException when I try to add the account.
Account account = new Account(user.getLogin(), 'packageName');
The thing I don't understand is about the type (in the second parameter).
What do I've to put in second parameter in order to make my code working.
Moreover, I'd like to know if I can add an acount simply with theses lines of code, or should I use a service like many example show ?
Thanks
EDIT - Full Exception Message
java.lang.SecurityException: caller uid 10047 is different than the authenticator's uid
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.accounts.IAccountManager$Stub$Proxy.addAccount(IAccountManager.java:580)
at android.accounts.AccountManager.addAccountExplicitly(AccountManager.java:565)
at fr.opendev.elisaG.activity.LoginActivity.isUserAuthorized(LoginActivity.java:113)
at fr.opendev.elisaG.activity.LoginActivity.access$500(LoginActivity.java:27)
at fr.opendev.elisaG.activity.LoginActivity$1.onClick(LoginActivity.java:70)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16964)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Android Live Wallpaper crashes on Amazon App Store Testing ActivityNotFoundException

I am trying to put my live wallpaper on Amazon App Store(This live wallpaper is already live on Google Play Store), However, when I uploaded same APK for testing on Amazon Developer site it reports following exception
03-06 06:00:50.741 7598 7598 E AndroidRuntime: FATAL EXCEPTION: main
03-06 06:00:50.741 7598 7598 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rrapps.heavensdoor/com.rrapps.heavensdoor.PreviewActivity}: android.content.ActivityNotFoundException: No Activity found to handle act=android.service.wallpaper.CHANGE_LIVE_WALLPAPER (has extras)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2229)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
at android.app.ActivityThread.access$600(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:151)
at android.app.ActivityThread.main(ActivityThread.java:5204)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle act=android.service.wallpaper.CHANGE_LIVE_WALLPAPER (has extras)
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1627)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at com.rrapps.heavensdoor.PreviewActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5170)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2182)
following is code where I am setting wallpaper
if (Build.VERSION.SDK_INT >= 16) {
/*
* Open live wallpaper preview (API Level 16 or greater).
*/
intent.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
String pkg = MyWallpaperService.class.getPackage().getName();
String cls = MyWallpaperService.class.getCanonicalName();
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(pkg, cls));
} else {
/*
* Open live wallpaper picker (API Level 15 or lower).
*
* Display a quick little message (toast) with instructions.
*/
intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
Resources res = getResources();
String hint = res.getString(R.string.picker_toast_prefix)
+ res.getString(R.string.lwp_name)
+ res.getString(R.string.picker_toast_suffix);
Toast toast = Toast.makeText(this, hint, Toast.LENGTH_LONG);
toast.show();
}
startActivityForResult(intent, 0);
I am not sure what the problem is. Any help is appreciated.
Android is a funny world and implicit intents unfortunately, vary more than we (developers) would like them to. Specially for Amazon devices, that are not required to comply with Google test suite. On my app, I've seen ActivityNotFoundException trying to launch the web-browser.
So my suggestion, even tho it doesn't actually fix the issue, it's just try catch it:
try{
startActivityForResult(intent, 0);
} catch(ActivityNotFoundException e) {
// why amazon, why?
}

AnalyticsService: java.lang.SecurityException: attempting to read gservices without permission

I've spent the entire day attempting to fix this, please find the stack trace below, coming from the Google Play Services lib. I changed nothing, i rebuilt the app today and ever since have been given this error. I've tried upgrading GPS to the latest version, rebuilding GPS, downgrading GPS to a previous version, removing various other libraries, explicitly adding the permission it requests and other such niceties... but NOTHING.
if ANYONE can please lend some advice i'd be forever grateful.
java.lang.RuntimeException: Unable to instantiate service
com.google.android.gms.analytics.service.AnalyticsService: java.lang.SecurityException: attempting to
read gservices without permission: Neither user 10064 nor current process has
com.google.android.providers.gsf.permission.READ_GSERVICES. at
android.app.ActivityThread.handleCreateService(ActivityThread.java:1929) at
android.app.ActivityThread.access$2500(ActivityThread.java:117) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:985) at
android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at
android.app.ActivityThread.main(ActivityThread.java:3683) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:507) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:895) at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653) at dalvik.system.NativeStart.main(Native
Method) Caused by: java.lang.SecurityException: attempting to read gservices without permission:
Neither user 10064 nor current process has
com.google.android.providers.gsf.permission.READ_GSERVICES. at
android.app.ContextImpl.enforce(ContextImpl.java:1289) at
android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1318) at
android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:395) at
imq.c(SourceFile:107) at imq.a(SourceFile:121) at blw.a(SourceFile:276) at blu.b(SourceFile:203) at
blo.c(SourceFile:135) at com.google.android.gms.analytics.service.AnalyticsService.<init
(SourceFile:53) at java.lang.Class.newInstanceImpl(Native Method) at
java.lang.Class.newInstance(Class.java:1409) at
android.app.ActivityThread.handleCreateService(ActivityThread.java:1926) ... 10 more

Android Service Exchange always crashs

I'm getting a crash always when I install or uninstall an app that use Sync Service, like Facebook, whatsup, etc.
"Unfortunately, Exchange Services has stopped."
I don't know why, but it just happens for some devices, in my case all of then are Android 4.4.2.
First I thought it's my app's fault, but it doesn't make sense once I uninstall my app and the problem continues happening for others apps.
Do you know something about it?
Thank you.
02-07 14:31:49.864 3015-3015/? E/ActivityThread﹕ Failed to find provider info for com.google.android.email.provider
02-07 14:31:49.864 3015-3015/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.google.android.exchange, PID: 3015
java.lang.RuntimeException: Unable to create application com.android.exchange.Exchange: java.lang.IllegalArgumentException: Unknown URI content://com.google.android.email.provider
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4347)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Unknown URI content://com.google.android.email.provider
at android.content.ContentResolver.call(ContentResolver.java:1352)
at com.android.exchange.Exchange.onCreate(Exchange.java:34)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
I found what was happening!
The problem occurs by device when there are sync accounts registered, but the Exchange Service cannot find any application to answer the URI, in my case it was "content://com.google.android.email.provider", to fix it I checked my disable applications and there was it, my default email application was disable. I just enable it again and the problem never occurs again.
Go to Settings > Apps > ALL> Exchange Services > Clear Cache and try opening it. When it opens, check once.
I had that problem. now I’m using a good app called Mailwise. it’s a free email app, very convenient for businesses, you can easily set up multiple email accounts, and it works great with Exchange.
https://play.google.com/store/apps/details?id=com.syntomo.email&hl=en

Categories

Resources