android 9.0 기본 APK 권한 추가 방법

10223 단어 android9.0apk권한
1.기본적으로 모든 권한 부여:
안 드 로 이 드 는 사용자 에 게 권한 을 추가 할 수 있 도록 동적 으로 요구 합 니 다.다음 코드 의 final boolean grantPermissions=(args.intallFlags)
& PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS) != 0;final boolean grantPermissions=true 로 바 꾸 면 됩 니 다.
파일 경로:framework\\base\services\\core\java\com\android\server\\pm\\PackageManager Service.java

case POST_INSTALL: {
                    if (DEBUG_INSTALL) Log.v(TAG, "Handling post-install for " + msg.arg1);

                    PostInstallData data = mRunningInstalls.get(msg.arg1);
                    final boolean didRestore = (msg.arg2 != 0);
                    mRunningInstalls.delete(msg.arg1);

                    if (data != null) {
                        InstallArgs args = data.args;
                        PackageInstalledInfo parentRes = data.res;
                        
                        /*final boolean grantPermissions = (args.installFlags
                                & PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS) != 0;
                        */
                        //   grantPermissions  true  
                        final boolean grantPermissions = true;
                        final boolean killApp = (args.installFlags
                                & PackageManager.INSTALL_DONT_KILL_APP) == 0;
                        final boolean virtualPreload = ((args.installFlags
                                & PackageManager.INSTALL_VIRTUAL_PRELOAD) != 0);
                        final String[] grantedPermissions = args.installGrantPermissions;

                        // Handle the parent package
                        handlePackagePostInstall(parentRes, grantPermissions, killApp,
                                virtualPreload, grantedPermissions, didRestore,
                                args.installerPackageName, args.observer);

                        // Handle the child packages
                        final int childCount = (parentRes.addedChildPackages != null)
                                ? parentRes.addedChildPackages.size() : 0;
                        for (int i = 0; i < childCount; i++) {
                            PackageInstalledInfo childRes = parentRes.addedChildPackages.valueAt(i);
                            handlePackagePostInstall(childRes, grantPermissions, killApp,
                                    virtualPreload, grantedPermissions, false /*didRestore*/,
                                    args.installerPackageName, args.observer);
                        }

                        // Log tracing if needed
                        if (args.traceMethod != null) {
                            Trace.asyncTraceEnd(TRACE_TAG_PACKAGE_MANAGER, args.traceMethod,
                                    args.traceCookie);
                        }
                    } else {
                        Slog.e(TAG, "Bogus post-install token " + msg.arg1);
                    }

                    Trace.asyncTraceEnd(TRACE_TAG_PACKAGE_MANAGER, "postInstall", msg.arg1);
                } break;
2.가방 이름 에 따라 권한 부여:
파일 경로:framework\\base\services\core\java\com\android\\server\pm\permission\\\\DefaultPermission GrantPolicy.java

--- a/frameworks/base/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
+++ b/frameworks/base/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
@@ -94,7 +94,7 @@ import java.util.Set;
  */
 public final class DefaultPermissionGrantPolicy {
     private static final String TAG = "DefaultPermGrantPolicy"; // must be <= 23 chars
-    private static final boolean DEBUG = false;
+    private static final boolean DEBUG = true;

     private static final int DEFAULT_FLAGS =
             PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
@@ -216,6 +216,7 @@ public final class DefaultPermissionGrantPolicy {
                 }
             }
         };
+        Slog.e(TAG,"vsoonbsp helloworld
"); mPermissionGrantedCallback = callback; mPermissionManager = permissionManager; mServiceInternal = LocalServices.getService(PackageManagerInternal.class); @@ -263,8 +264,55 @@ public final class DefaultPermissionGrantPolicy { } } + // apk + private static final String PCK_NAME_MICROSOFT = "com.microsoft.translator"; + private static final String PCK_NAME_TTS = "com.google.android.tts"; + private static final String PCK_NAME_SEARCH = "com.google.android.googlequicksearchbox"; + + private void grantPermissionsToCustomApp(int userId){ + try{ + PackageParser.Package customPackage = getSystemPackage(PCK_NAME_MICROSOFT); + if ((customPackage != null) && doesPackageSupportRuntimePermissions(customPackage)) { + grantRuntimePermissions(customPackage, LOCATION_PERMISSIONS, userId); + grantRuntimePermissions(customPackage, STORAGE_PERMISSIONS, userId); + grantRuntimePermissions(customPackage, MICROPHONE_PERMISSIONS, userId); + } + + customPackage = getSystemPackage(PCK_NAME_MICROSOFT); + if ((customPackage != null) && doesPackageSupportRuntimePermissions(customPackage)) { + grantRuntimePermissions(customPackage, LOCATION_PERMISSIONS, userId); + grantRuntimePermissions(customPackage, STORAGE_PERMISSIONS, userId); + grantRuntimePermissions(customPackage, MICROPHONE_PERMISSIONS, userId); + } + + customPackage = getSystemPackage(PCK_NAME_SEARCH); + if ((customPackage != null) && doesPackageSupportRuntimePermissions(customPackage)) { + grantRuntimePermissions(customPackage, LOCATION_PERMISSIONS, userId); + grantRuntimePermissions(customPackage, STORAGE_PERMISSIONS, userId); + grantRuntimePermissions(customPackage, MICROPHONE_PERMISSIONS, userId); + } + + + }catch(Exception e) { + e.printStackTrace(); + } + } + public void grantDefaultPermissions(int userId) { grantPermissionsToSysComponentsAndPrivApps(userId); + grantPermissionsToCustomApp(userId); grantDefaultSystemHandlerPermissions(userId); grantDefaultPermissionExceptions(userId); }
3.default-permissions-google.xml 을 통 해
이 파일 을 컴 파일 할 때/system/etc/default-permissions/default-permissions-google.xml 에 컴 파일 해 야 합 니 다.
Android.mk 를 사용 할 수 있 는 PRODUCTCOPY_FILES 방식 복사.
default-permissions-google.xml 에 관 한 것 은 구 글 을 참고 할 수 있 습 니 다.https://source.android.google.cn/devices/tech/config/perms-whitelist

<exception
            package="com.google.android.tts"
            sha256-cert-digest="56:BE:13:2B:78:06:56:FE:24:44:CD:34:32:6E:B5:D7:AA:C9:1D:20:96:AB:F0:FE:67:3A:99:27:06:22:EC:87">
        <!-- External storage -->
        <permission name="android.permission.READ_EXTERNAL_STORAGE" fixed="false"/>
        <permission name="android.permission.WRITE_EXTERNAL_STORAGE" fixed="false"/>
        <!-- Contacts -->
        <permission name="android.permission.READ_CONTACTS" fixed="false"/>
        <permission name="android.permission.WRITE_CONTACTS" fixed="false"/>
        <!-- microphone -->
        <permission name="android.permission.RECORD_AUDIO" fixed="false"/>
    </exception>

   <exception
            package="com.google.android.googlequicksearchbox"
            sha256-cert-digest="56:BE:13:2B:78:06:56:FE:24:44:CD:34:32:6E:B5:D7:AA:C9:1D:20:96:AB:F0:FE:67:3A:99:27:06:22:EC:87">
        <!-- External storage -->
        <permission name="android.permission.READ_EXTERNAL_STORAGE" fixed="false"/>
        <permission name="android.permission.WRITE_EXTERNAL_STORAGE" fixed="false"/>
        <!-- Contacts -->
        <permission name="android.permission.READ_CONTACTS" fixed="false"/>
        <permission name="android.permission.WRITE_CONTACTS" fixed="false"/>
        <!-- microphone -->
        <permission name="android.permission.RECORD_AUDIO" fixed="false"/>
    </exception>

   <exception
            package="com.microsoft.translator"
            sha256-cert-digest="56:BE:13:2B:78:06:56:FE:24:44:CD:34:32:6E:B5:D7:AA:C9:1D:20:96:AB:F0:FE:67:3A:99:27:06:22:EC:87">
        <!-- External storage -->
        <permission name="android.permission.READ_EXTERNAL_STORAGE" fixed="false"/>
        <permission name="android.permission.WRITE_EXTERNAL_STORAGE" fixed="false"/>
        <!-- Contacts -->
        <permission name="android.permission.READ_CONTACTS" fixed="false"/>
        <permission name="android.permission.WRITE_CONTACTS" fixed="false"/>
        <!-- microphone -->
        <permission name="android.permission.RECORD_AUDIO" fixed="false"/>
    </exception>
이상 은 안 드 로 이 드 9.0 기본 apk 권한 추가 에 대한 상세 한 내용 입 니 다.안 드 로 이 드 9.0 기본 권한 추가 에 관 한 자 료 는 다른 관련 글 을 주목 하 십시오!

좋은 웹페이지 즐겨찾기