Java Code Examples for android.content.pm.ApplicationInfo#loadSafeLabel()

The following examples show how to use android.content.pm.ApplicationInfo#loadSafeLabel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnsupportedDisplaySizeDialog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public UnsupportedDisplaySizeDialog(final AppWarnings manager, Context context,
        ApplicationInfo appInfo) {
    mPackageName = appInfo.packageName;

    final PackageManager pm = context.getPackageManager();
    final CharSequence label = appInfo.loadSafeLabel(pm);
    final CharSequence message = context.getString(
            R.string.unsupported_display_size_message, label);

    mDialog = new AlertDialog.Builder(context)
            .setPositiveButton(R.string.ok, null)
            .setMessage(message)
            .setView(R.layout.unsupported_display_size_dialog_content)
            .create();

    // Ensure the content view is prepared.
    mDialog.create();

    final Window window = mDialog.getWindow();
    window.setType(WindowManager.LayoutParams.TYPE_PHONE);

    // DO NOT MODIFY. Used by CTS to verify the dialog is displayed.
    window.getAttributes().setTitle("UnsupportedDisplaySizeDialog");

    final CheckBox alwaysShow = mDialog.findViewById(R.id.ask_checkbox);
    alwaysShow.setChecked(true);
    alwaysShow.setOnCheckedChangeListener((buttonView, isChecked) -> manager.setPackageFlag(
            mPackageName, AppWarnings.FLAG_HIDE_DISPLAY_SIZE, !isChecked));
}
 
Example 2
Source File: UnsupportedCompileSdkDialog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public UnsupportedCompileSdkDialog(final AppWarnings manager, Context context,
        ApplicationInfo appInfo) {
    mPackageName = appInfo.packageName;

    final PackageManager pm = context.getPackageManager();
    final CharSequence label = appInfo.loadSafeLabel(pm);
    final CharSequence message = context.getString(R.string.unsupported_compile_sdk_message,
            label);

    final AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setPositiveButton(R.string.ok, null)
            .setMessage(message)
            .setView(R.layout.unsupported_compile_sdk_dialog_content);

    // If we might be able to update the app, show a button.
    final Intent installerIntent = AppInstallerUtil.createIntent(context, appInfo.packageName);
    if (installerIntent != null) {
            builder.setNeutralButton(R.string.unsupported_compile_sdk_check_update,
                    (dialog, which) -> context.startActivity(installerIntent));
    }

    // Ensure the content view is prepared.
    mDialog = builder.create();
    mDialog.create();

    final Window window = mDialog.getWindow();
    window.setType(WindowManager.LayoutParams.TYPE_PHONE);

    // DO NOT MODIFY. Used by CTS to verify the dialog is displayed.
    window.getAttributes().setTitle("UnsupportedCompileSdkDialog");

    final CheckBox alwaysShow = mDialog.findViewById(R.id.ask_checkbox);
    alwaysShow.setChecked(true);
    alwaysShow.setOnCheckedChangeListener((buttonView, isChecked) -> manager.setPackageFlag(
            mPackageName, AppWarnings.FLAG_HIDE_COMPILE_SDK, !isChecked));
}
 
Example 3
Source File: DeprecatedTargetSdkVersionDialog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public DeprecatedTargetSdkVersionDialog(final AppWarnings manager, Context context,
        ApplicationInfo appInfo) {
    mPackageName = appInfo.packageName;

    final PackageManager pm = context.getPackageManager();
    final CharSequence label = appInfo.loadSafeLabel(pm);
    final CharSequence message = context.getString(R.string.deprecated_target_sdk_message);

    final AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setPositiveButton(R.string.ok, (dialog, which) ->
                manager.setPackageFlag(
                        mPackageName, AppWarnings.FLAG_HIDE_DEPRECATED_SDK, true))
            .setMessage(message)
            .setTitle(label);

    // If we might be able to update the app, show a button.
    final Intent installerIntent = AppInstallerUtil.createIntent(context, appInfo.packageName);
    if (installerIntent != null) {
        builder.setNeutralButton(R.string.deprecated_target_sdk_app_store,
                (dialog, which) -> {
                    context.startActivity(installerIntent);
                });
    }

    // Ensure the content view is prepared.
    mDialog = builder.create();
    mDialog.create();

    final Window window = mDialog.getWindow();
    window.setType(WindowManager.LayoutParams.TYPE_PHONE);

    // DO NOT MODIFY. Used by CTS to verify the dialog is displayed.
    window.getAttributes().setTitle("DeprecatedTargetSdkVersionDialog");
}
 
Example 4
Source File: AppSecurityPermissions.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void setPermissions(List<MyPermissionInfo> permList) {
    if (permList != null) {
        // First pass to group permissions
        for (MyPermissionInfo pInfo : permList) {
            if(localLOGV) Log.i(TAG, "Processing permission:"+pInfo.name);
            if(!isDisplayablePermission(pInfo, pInfo.mNewReqFlags, pInfo.mExistingReqFlags)) {
                if(localLOGV) Log.i(TAG, "Permission:"+pInfo.name+" is not displayable");
                continue;
            }
            MyPermissionGroupInfo group = mPermGroups.get(pInfo.group);
            if (group != null) {
                pInfo.mLabel = pInfo.loadSafeLabel(mPm, 20000,
                        PackageItemInfo.SAFE_LABEL_FLAG_TRIM
                        | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE);
                addPermToList(group.mAllPermissions, pInfo);
                if (pInfo.mNew) {
                    addPermToList(group.mNewPermissions, pInfo);
                }
            }
        }
    }

    for (MyPermissionGroupInfo pgrp : mPermGroups.values()) {
        if (pgrp.labelRes != 0 || pgrp.nonLocalizedLabel != null) {
            pgrp.mLabel = pgrp.loadSafeLabel(mPm, 20000, PackageItemInfo.SAFE_LABEL_FLAG_TRIM
                    | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE);
        } else {
            ApplicationInfo app;
            try {
                app = mPm.getApplicationInfo(pgrp.packageName, 0);
                pgrp.mLabel = app.loadSafeLabel(mPm, 20000, PackageItemInfo.SAFE_LABEL_FLAG_TRIM
                        | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE);
            } catch (NameNotFoundException e) {
                pgrp.mLabel = pgrp.loadSafeLabel(mPm, 20000,
                        PackageItemInfo.SAFE_LABEL_FLAG_TRIM
                        | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE);
            }
        }
        mPermGroupsList.add(pgrp);
    }
    Collections.sort(mPermGroupsList, mPermGroupComparator);
}