android.content.pm.PackageUserState源码实例Demo

类android.content.pm.PackageUserState源码实例Demo

下面列出了android.content.pm.PackageUserState 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: PackageSettingBase.java
public PackageUserState readUserState(int userId) {
    PackageUserState state = userState.get(userId);
    if (state == null) {
        return DEFAULT_USER_STATE;
    }
    state.categoryHint = categoryHint;
    return state;
}
 
源代码2 项目: android_9.0.0_r45   文件: PackageSettingBase.java
void setSuspended(boolean suspended, String suspendingPackage, String dialogMessage,
        PersistableBundle appExtras, PersistableBundle launcherExtras, int userId) {
    final PackageUserState existingUserState = modifyUserState(userId);
    existingUserState.suspended = suspended;
    existingUserState.suspendingPackage = suspended ? suspendingPackage : null;
    existingUserState.dialogMessage = suspended ? dialogMessage : null;
    existingUserState.suspendedAppExtras = suspended ? appExtras : null;
    existingUserState.suspendedLauncherExtras = suspended ? launcherExtras : null;
}
 
源代码3 项目: android_9.0.0_r45   文件: PackageSettingBase.java
void setUserState(int userId, long ceDataInode, int enabled, boolean installed, boolean stopped,
        boolean notLaunched, boolean hidden, boolean suspended, String suspendingPackage,
        String dialogMessage, PersistableBundle suspendedAppExtras,
        PersistableBundle suspendedLauncherExtras, boolean instantApp,
        boolean virtualPreload, String lastDisableAppCaller,
        ArraySet<String> enabledComponents, ArraySet<String> disabledComponents,
        int domainVerifState, int linkGeneration, int installReason,
        String harmfulAppWarning) {
    PackageUserState state = modifyUserState(userId);
    state.ceDataInode = ceDataInode;
    state.enabled = enabled;
    state.installed = installed;
    state.stopped = stopped;
    state.notLaunched = notLaunched;
    state.hidden = hidden;
    state.suspended = suspended;
    state.suspendingPackage = suspendingPackage;
    state.dialogMessage = dialogMessage;
    state.suspendedAppExtras = suspendedAppExtras;
    state.suspendedLauncherExtras = suspendedLauncherExtras;
    state.lastDisableAppCaller = lastDisableAppCaller;
    state.enabledComponents = enabledComponents;
    state.disabledComponents = disabledComponents;
    state.domainVerificationStatus = domainVerifState;
    state.appLinkGeneration = linkGeneration;
    state.installReason = installReason;
    state.instantApp = instantApp;
    state.virtualPreload = virtualPreload;
    state.harmfulAppWarning = harmfulAppWarning;
}
 
源代码4 项目: android_9.0.0_r45   文件: PackageSettingBase.java
PackageUserState modifyUserStateComponents(int userId, boolean disabled, boolean enabled) {
    PackageUserState state = modifyUserState(userId);
    if (disabled && state.disabledComponents == null) {
        state.disabledComponents = new ArraySet<String>(1);
    }
    if (enabled && state.enabledComponents == null) {
        state.enabledComponents = new ArraySet<String>(1);
    }
    return state;
}
 
源代码5 项目: android_9.0.0_r45   文件: PackageSettingBase.java
boolean enableComponentLPw(String componentClassName, int userId) {
    PackageUserState state = modifyUserStateComponents(userId, false, true);
    boolean changed = state.disabledComponents != null
            ? state.disabledComponents.remove(componentClassName) : false;
    changed |= state.enabledComponents.add(componentClassName);
    return changed;
}
 
源代码6 项目: android_9.0.0_r45   文件: PackageSettingBase.java
boolean disableComponentLPw(String componentClassName, int userId) {
    PackageUserState state = modifyUserStateComponents(userId, true, false);
    boolean changed = state.enabledComponents != null
            ? state.enabledComponents.remove(componentClassName) : false;
    changed |= state.disabledComponents.add(componentClassName);
    return changed;
}
 
源代码7 项目: android_9.0.0_r45   文件: PackageSettingBase.java
boolean restoreComponentLPw(String componentClassName, int userId) {
    PackageUserState state = modifyUserStateComponents(userId, true, true);
    boolean changed = state.disabledComponents != null
            ? state.disabledComponents.remove(componentClassName) : false;
    changed |= state.enabledComponents != null
            ? state.enabledComponents.remove(componentClassName) : false;
    return changed;
}
 
源代码8 项目: android_9.0.0_r45   文件: PackageSettingBase.java
int getCurrentEnabledStateLPr(String componentName, int userId) {
    PackageUserState state = readUserState(userId);
    if (state.enabledComponents != null && state.enabledComponents.contains(componentName)) {
        return COMPONENT_ENABLED_STATE_ENABLED;
    } else if (state.disabledComponents != null
            && state.disabledComponents.contains(componentName)) {
        return COMPONENT_ENABLED_STATE_DISABLED;
    } else {
        return COMPONENT_ENABLED_STATE_DEFAULT;
    }
}
 
源代码9 项目: android_9.0.0_r45   文件: PackageSettingBase.java
void setDomainVerificationStatusForUser(final int status, int generation, int userId) {
    PackageUserState state = modifyUserState(userId);
    state.domainVerificationStatus = status;
    if (status == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) {
        state.appLinkGeneration = generation;
    }
}
 
源代码10 项目: android_9.0.0_r45   文件: PackageSettingBase.java
protected void writeUsersInfoToProto(ProtoOutputStream proto, long fieldId) {
    int count = userState.size();
    for (int i = 0; i < count; i++) {
        final long userToken = proto.start(fieldId);
        final int userId = userState.keyAt(i);
        final PackageUserState state = userState.valueAt(i);
        proto.write(PackageProto.UserInfoProto.ID, userId);
        final int installType;
        if (state.instantApp) {
            installType = PackageProto.UserInfoProto.INSTANT_APP_INSTALL;
        } else if (state.installed) {
            installType = PackageProto.UserInfoProto.FULL_APP_INSTALL;
        } else {
            installType = PackageProto.UserInfoProto.NOT_INSTALLED_FOR_USER;
        }
        proto.write(PackageProto.UserInfoProto.INSTALL_TYPE, installType);
        proto.write(PackageProto.UserInfoProto.IS_HIDDEN, state.hidden);
        proto.write(PackageProto.UserInfoProto.IS_SUSPENDED, state.suspended);
        if (state.suspended) {
            proto.write(PackageProto.UserInfoProto.SUSPENDING_PACKAGE, state.suspendingPackage);
        }
        proto.write(PackageProto.UserInfoProto.IS_STOPPED, state.stopped);
        proto.write(PackageProto.UserInfoProto.IS_LAUNCHED, !state.notLaunched);
        proto.write(PackageProto.UserInfoProto.ENABLED_STATE, state.enabled);
        proto.write(
                PackageProto.UserInfoProto.LAST_DISABLED_APP_CALLER,
                state.lastDisableAppCaller);
        proto.end(userToken);
    }
}
 
源代码11 项目: GPT   文件: ApkTargetMapping.java
/**
     * generateActivityInfo
     *
     * @param p     PackageParser.Package
     * @param pi    PackageInfo
     * @param flags flags
     */
    private void generateActivityInfo(PackageParser.Package p, PackageInfo pi, int flags) {
        PackageUserState state = new PackageUserState();

        if ((flags & PackageManager.GET_ACTIVITIES) != 0) {
            int N = p.activities.size();
            if (N > 0) {
                if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.activities = new ActivityInfo[N];
                } else {
                    int num = 0;
                    for (int i = 0; i < N; i++) {
                        if (p.activities.get(i).info.enabled) num++;
                    }
                    pi.activities = new ActivityInfo[num];
                }
                for (int i = 0, j = 0; i < N; i++) {
                    final Activity activity = p.activities.get(i);
                    if (activity.info.enabled
                            || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                        pi.activities[j++] = PackageParser.generateActivityInfo(activity, flags, state, 0);
//                        try {
//                            pi.activities[j++] = JavaCalls.callStaticMethodOrThrow(PackageParser.class, "generateActivityInfo",
//                                    activity, flags, state, 0);
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        } 
                    }
                }
            }
        }
    }
 
源代码12 项目: GPT   文件: ApkTargetMapping.java
/**
     * generateServiceInfo
     *
     * @param p     PackageParser.Package
     * @param pi    PackageInfo
     * @param flags flags
     */
    private void generateServiceInfo(PackageParser.Package p, PackageInfo pi, int flags) {
        PackageUserState state = new PackageUserState();
        if ((flags & PackageManager.GET_SERVICES) != 0) {
            int N = p.services.size();
            if (N > 0) {
                if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.services = new ServiceInfo[N];
                } else {
                    int num = 0;
                    for (int i = 0; i < N; i++) {
                        if (p.services.get(i).info.enabled) num++;
                    }
                    pi.services = new ServiceInfo[num];
                }
                for (int i = 0, j = 0; i < N; i++) {
                    final Service service = p.services.get(i);
                    if (service.info.enabled
                            || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                        pi.services[j++] = PackageParser.generateServiceInfo(p.services.get(i), flags,
                                state, 0);
//                        try {
//                            pi.services[j++] = JavaCalls.callStaticMethodOrThrow(PackageParser.class, "generateServiceInfo",
//                                    p.services.get(i), flags, state, 0);
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        } 
                    }
                }
            }
        }
    }
 
源代码13 项目: GPT   文件: ApkTargetMapping.java
/**
     * generateProviderInfo
     *
     * @param p     PackageParser.Package
     * @param pi    PackageInfo
     * @param flags flags
     */
    private void generateProviderInfo(PackageParser.Package p, PackageInfo pi, int flags) {
        PackageUserState state = new PackageUserState();
        if ((flags & PackageManager.GET_PROVIDERS) != 0) {
            int N = p.providers.size();
            if (N > 0) {
                if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.providers = new ProviderInfo[N];
                } else {
                    int num = 0;
                    for (int i = 0; i < N; i++) {
                        if (p.providers.get(i).info.enabled) num++;
                    }
                    pi.providers = new ProviderInfo[num];
                }
                for (int i = 0, j = 0; i < N; i++) {
                    final Provider provider = p.providers.get(i);
                    if (provider.info.enabled
                            || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                        pi.providers[j++] = PackageParser.generateProviderInfo(p.providers.get(i), flags,
                                state, 0);
//                        try {
//                            pi.providers[j++] = JavaCalls.callStaticMethodOrThrow(PackageParser.class, "generateProviderInfo",
//                                    p.providers.get(i), flags, state, 0);
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        } 
                    }
                }
            }
        }


    }
 
源代码14 项目: GPT   文件: ApkTargetMapping.java
/**
     * generateReceiverInfo
     *
     * @param p     PackageParser.Package
     * @param pi    PackageInfo
     * @param flags flags
     */
    private void generateReceiverInfo(PackageParser.Package p, PackageInfo pi, int flags) {
        PackageUserState state = new PackageUserState();
        if ((flags & PackageManager.GET_RECEIVERS) != 0) {
            int N = p.receivers.size();
            if (N > 0) {
                if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.receivers = new ActivityInfo[N];
                } else {
                    int num = 0;
                    for (int i = 0; i < N; i++) {
                        if (p.receivers.get(i).info.enabled) num++;
                    }
                    pi.receivers = new ActivityInfo[num];
                }
                for (int i = 0, j = 0; i < N; i++) {
                    final Activity activity = p.receivers.get(i);
                    if (activity.info.enabled
                            || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                        pi.receivers[j++] = PackageParser.generateActivityInfo(p.receivers.get(i), flags, state, 0);
//                        try {
//                            pi.receivers[j++] = JavaCalls.callStaticMethodOrThrow(PackageParser.class,
//                                    "generateActivityInfo", p.receivers.get(i), flags, state, 0);
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
                    }
                }
            }
        }
    }
 
源代码15 项目: android_9.0.0_r45   文件: PackageSettingBase.java
void setEnabled(int state, int userId, String callingPackage) {
    PackageUserState st = modifyUserState(userId);
    st.enabled = state;
    st.lastDisableAppCaller = callingPackage;
}
 
源代码16 项目: android_9.0.0_r45   文件: PackageSettingBase.java
/** Only use for testing. Do NOT use in production code. */
@VisibleForTesting
SparseArray<PackageUserState> getUserState() {
    return userState;
}
 
源代码17 项目: android_9.0.0_r45   文件: PackageSettingBase.java
long getDomainVerificationStatusForUser(int userId) {
    PackageUserState state = readUserState(userId);
    long result = (long) state.appLinkGeneration;
    result |= ((long) state.domainVerificationStatus) << 32;
    return result;
}
 
源代码18 项目: android_9.0.0_r45   文件: PackageSettingBase.java
void setHarmfulAppWarning(int userId, String harmfulAppWarning) {
    PackageUserState userState = modifyUserState(userId);
    userState.harmfulAppWarning = harmfulAppWarning;
}
 
源代码19 项目: android_9.0.0_r45   文件: PackageSettingBase.java
String getHarmfulAppWarning(int userId) {
    PackageUserState userState = readUserState(userId);
    return userState.harmfulAppWarning;
}
 
源代码20 项目: GPT   文件: ApkTargetMapping.java
/**
 * getPackageArchiveInfo
 *
 * @param parser          android.content.pm.PackageParser
 * @param pkg             PackageParser.Package
 * @param archiveFilePath archiveFilePath
 * @param flags           flags
 * @return PackageInfo
 */
public PackageInfo getPackageArchiveInfo(android.content.pm.PackageParser parser, PackageParser.Package pkg,
                                         String archiveFilePath, int flags) {
    PackageInfo packageInfo = null;
    if ((flags & PackageManager.GET_SIGNATURES) != 0) {
        // 2.3 4.0 4.1 4.2 4.4
        parser.collectCertificates(pkg, 0);
        // 5.0
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            parser.collectManifestDigest(pkg);
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // 4.2 4.3 4.4 5.0 6.0
        PackageUserState state = new PackageUserState();
        //packageInfo = PackageParser.generatePackageInfo(pkg, null, flags, 0, 0, null, state);
        try {
            // 这里使用反射。因为 permission 参数 在 5.0 5.1 6.0 上参数不同,但是我们传入的为 null
            packageInfo = JavaCalls.callStaticMethodOrThrow(PackageParser.class, "generatePackageInfo",
                    pkg, null, flags, 0L, 0L, null, state);
        } catch (Exception e) {
            if (Constants.DEBUG) {
                e.printStackTrace();
            }
            String methodInfo = JavaCalls
                    .getMethodToString(JavaCalls.getMethodFromClass(PackageParser.class, "generatePackageInfo"));
            if (methodInfo == null) {
                methodInfo = "";
            }
            throw new RuntimeException("generatePackageInfo get exception, " + methodInfo, e);
        }
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // 4.1
        packageInfo = PackageParser.generatePackageInfo(pkg, null, flags, 0, 0, null, false, 0);
    } else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        //  2.3 4.0
        packageInfo = PackageParser.generatePackageInfo(pkg, null, flags, 0, 0);
    }

    return packageInfo;
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 同包方法