List of usage examples for android.widget AppSecurityPermissions AppSecurityPermissions
public AppSecurityPermissions(Context context, PackageInfo info)
From source file:com.android.packageinstaller.GrantActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mPm = getPackageManager();//from w w w .j a v a2s . com mRequestingPackage = this.getCallingPackage(); requested_permissions = getRequestedPermissions(); if (requested_permissions.length == 0) { // The grant request was empty. Return success setResult(RESULT_OK); finish(); return; } PackageInfo pkgInfo = getUpdatedPackageInfo(); AppSecurityPermissions perms = new AppSecurityPermissions(this, pkgInfo); if (perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) == 0) { // The updated permissions dialog said there are no new permissions. // This should never occur if requested_permissions.length > 0, // but we check for it anyway, just in case. setResult(RESULT_OK); finish(); return; } setContentView(R.layout.install_start); ((TextView) findViewById(R.id.install_confirm_question)).setText(R.string.grant_confirm_question); PackageUtil.AppSnippet as = new PackageUtil.AppSnippet(mPm.getApplicationLabel(pkgInfo.applicationInfo), mPm.getApplicationIcon(pkgInfo.applicationInfo)); PackageUtil.initSnippetForNewApp(this, as, R.id.app_snippet); mOk = (Button) findViewById(R.id.ok_button); mOk.setText(R.string.ok); mCancel = (Button) findViewById(R.id.cancel_button); mOk.setOnClickListener(this); mCancel.setOnClickListener(this); TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup(); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager); View newTab = perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW); View allTab = getPermissionList(perms); adapter.addTab(tabHost.newTabSpec("new").setIndicator(getText(R.string.newPerms)), newTab); adapter.addTab(tabHost.newTabSpec("all").setIndicator(getText(R.string.allPerms)), allTab); }
From source file:com.android.packageinstaller.PackageInstallerActivity.java
private void startInstallConfirm() { TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup();/*w w w. j a va 2 s. c o m*/ tabHost.setVisibility(View.VISIBLE); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager); // If the app supports runtime permissions the new permissions will // be requested at runtime, hence we do not show them at install. boolean supportsRuntimePermissions = mPkgInfo.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.M; boolean permVisible = false; mScrollView = null; mOkCanInstall = false; int msg = 0; AppSecurityPermissions perms = new AppSecurityPermissions(this, mPkgInfo); final int N = perms.getPermissionCount(AppSecurityPermissions.WHICH_ALL); if (mAppInfo != null) { msg = (mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_question_update_system : R.string.install_confirm_question_update; mScrollView = new CaffeinatedScrollView(this); mScrollView.setFillViewport(true); boolean newPermissionsFound = false; if (!supportsRuntimePermissions) { newPermissionsFound = (perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0); if (newPermissionsFound) { permVisible = true; mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW)); } } if (!supportsRuntimePermissions && !newPermissionsFound) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); TextView label = (TextView) inflater.inflate(R.layout.label, null); label.setText(R.string.no_new_perms); mScrollView.addView(label); } adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView); } else { findViewById(R.id.tabscontainer).setVisibility(View.GONE); findViewById(R.id.spacer).setVisibility(View.VISIBLE); } if (!supportsRuntimePermissions && N > 0) { permVisible = true; LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View root = inflater.inflate(R.layout.permissions_list, null); if (mScrollView == null) { mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview); } ((ViewGroup) root.findViewById(R.id.permission_list)) .addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_ALL)); adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root); } if (!permVisible) { if (mAppInfo != null) { // This is an update to an application, but there are no // permissions at all. msg = (mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_question_update_system_no_perms : R.string.install_confirm_question_update_no_perms; findViewById(R.id.spacer).setVisibility(View.VISIBLE); } else { // This is a new application with no permissions. msg = R.string.install_confirm_question_no_perms; } tabHost.setVisibility(View.INVISIBLE); mScrollView = null; } if (msg != 0) { ((TextView) findViewById(R.id.install_confirm_question)).setText(msg); } mInstallConfirm.setVisibility(View.VISIBLE); mOk.setEnabled(true); if (mScrollView == null) { // There is nothing to scroll view, so the ok button is immediately // set to install. mOk.setText(R.string.install); mOkCanInstall = true; } else { mScrollView.setFullScrollAction(new Runnable() { @Override public void run() { mOk.setText(R.string.install); mOkCanInstall = true; } }); } }