Reputation: 45
I get this error when running my app. I also included the permission for surfaceFlinger in manifest.xml
"uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER"
but still it give the same error " can't access the SurfaceFlinger"
in LogCat.
Basically i want to run the Development setting code in Dev tools.
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
try {
Class partypes[] = new Class[1];
partypes[0] = String.class;
Method getService= ServiceManager.getMethod("getService", partypes );
Object arglist[] = new Object[1];
arglist[0] = "SurfaceFlinger";
IBinder flinger= (IBinder)getService.invoke(smObject, arglist );
// IBinder flinger = ServiceManager.getService("SurfaceFlinger");
if (flinger != null) {
Parcel data = Parcel.obtain();
data.writeInterfaceToken("android.ui.ISurfaceComposer");
data.writeInt(isChecked ? 1 : 0);
flinger.transact(mCode, data, null, 0);
data.recycle();
updateFlingerOptions();
}
} catch (RemoteException ex) {
}
**catch (SecurityException e) {
// TODO Auto-generated catch block
String err=e.toString();
Toast.makeText(DevelopmentSetting.this, err, Toast.LENGTH_SHORT).show();
}**
catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
In catch SecurityException it gives the error java.lang.securityException but logcat it says permission denied : can't access surfaceFlinger.
and the manifest.xml is here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nustian.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER"/>
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".DevelopmentSetting"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Somebody help me.
Upvotes: 2
Views: 18445
Reputation: 31
As a workaround, add this to your manifest file. UID media is able to use the surface flinger APIs, so sharing UID with it will allow your app to use it as well.
coreApp="true"
android:sharedUserId="android.uid.media"
Upvotes: 3
Reputation: 511
Your app needs to be signed with the platform certificate to access this permission. Only system apps generally have this. More info here:
https://groups.google.com/forum/#!topic/android-porting/aN6D_vL9xxE
Upvotes: 4
Reputation: 68187
Don't forget to add its relative permission:
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />
Upvotes: 0