3

Ich entwickle eine Anwendung, die diese Berechtigung benötigen: android.permission.MANAGE_USB.permission.android.MANAGE_USB funktioniert in Jellybean aber nicht in Lollipop OS


Ich weiß, dass diese Erlaubnis nur bei System Application gegeben wird.

Wenn ich die Anwendung als Systemanwendung in Android 4.1.2 installieren, funktioniert die Anwendung gut.

Aber wenn ich versuche, es als System-App in Android 5.1 zu installieren, dann die Debug-Protokoll druckt, dass ich nicht die Erlaubnis:

Fehler:

W/System.err: java.lang.SecurityException: 
Neither user 10074 nor current process has android.permission.MANAGE_USB. 

für jedermann ist weiß, warum es mir diesen Fehler in Android 5.1 gibt?

Manifest:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.app"> 

<uses-permission android:name="android.permission.MANAGE_USB" 
    android:protectionLevel="signature" /> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="android.permission.GET_TASKS"/> 
<permission android:name="android.permission.SET_TIME" 
android:protectionLevel="signatureOrSystem" 
    /> 
<uses-feature android:name="android.hardware.usb.host" 
    android:required="true"/> 


<application 
    android:name=".services.AppContext" 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:largeHeap="true" 
    android:supportsRtl="true" 
    android:hardwareAccelerated="false" 
    android:theme="@style/AppTheme"> 
    <service android:name=".services.KioskService" android:exported="false"/> 
    <activity 
     android:name=".MainActivity" 
     android:launchMode="singleInstance" 
     android:stateNotNeeded="true" 
     android:screenOrientation="sensorLandscape"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.HOME" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <service 
     android:name="com.example.app.services.UsbService" 
     android:enabled="true"> 
    </service> 

    <receiver android:name=".services.PowerDisconnectReceiver"> 
     <intent-filter> 
      <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/> 
     </intent-filter> 
    </receiver> 

    <receiver android:name=".services.UsbPermissionReceiver"> 
     <intent-filter> 
      <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/> 
     </intent-filter> 
    </receiver> 

</application> 

</manifest> 
+2

Können Sie Ihre AndroidManifest.xml veröffentlichen? –

+1

Sind beide Geräte verwurzelt? Außerdem ist es wichtig, das Manifest zu zeigen, oder wir können nur spekulieren. – Mauker

+0

ok, ich habe das Manifest hinzugefügt. ja beide Geräte sind verwurzelt. Ich habe die Anwendung im System/App-Ordner mit 644 Berechtigungen installiert. –

Antwort

3

Ich würde versuchen, android:protectionLevel zu ändern signatureOrSystem:

A permission that the system grants only to applications that are in the Android system image or that are signed with the same certificate as the application that declared the permission. Please avoid using this option, as the signature protection level should be sufficient for most needs and works regardless of exactly where applications are installed. The "signatureOrSystem" permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together.

Für signature:

A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval.

Ich verstehe, dass Sie keinen Zugriff auf die Signaturschlüssel haben Wird von jedem verwendet, der das Android-Betriebssystem kompiliert hat Bild, das Sie in Ihren Geräten verwenden, so wird signatureprotectionLevel nicht übereinstimmen und Ihnen nicht die Berechtigung gewähren.

Siehe https://developer.android.com/guide/topics/manifest/permission-element.html

aktualisieren: Für Vollständigkeit, ich hinzufüge @ carlo.S Kommentare zur Antwort:

In Lollipop, an app to be considered as a system application needs to be installed under the system/priv-app folder and not system/app folder like in Android 4.2.2! Also, app needs to have 644 permissions.

Natürlich muss das Gerät verwurzelt sein.

+0

Was meinen Sie mit _ "Sie müssen auf den gleichen Signaturschlüssel zugreifen wie Android OS-Entwickler" _? –

+0

Ich meine den Schlüssel, der verwendet wurde, um die APK zu signieren. Dies ist ein öffentlicher/privater Schlüssel, der von jedem verwendet wird, der das von Ihnen verwendete Android-Bild kompiliert. Ich habe meiner Antwort eine Klarstellung hinzugefügt. –

+0

ohne die "Schutzstufe" die App verwendet, um in älteren Versionen von Android zu arbeiten, und ich verstehe nicht, warum in Lollipop funktioniert es nicht mehr ... –

Verwandte Themen