List of usage examples for android.widget AppSecurityPermissions getPermissionCount
public int getPermissionCount(int which)
From source file:com.android.packageinstaller.GrantActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mPm = getPackageManager();/*from w w w .jav a2 s.c o m*/ 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:org.fdroid.fdroid.installer.InstallConfirmActivity.java
private void startInstallConfirm() { final Drawable appIcon = mAppDiff.mPkgInfo.applicationInfo.loadIcon(mPm); final String appLabel = (String) mAppDiff.mPkgInfo.applicationInfo.loadLabel(mPm); View appSnippet = findViewById(R.id.app_snippet); ((ImageView) appSnippet.findViewById(R.id.app_icon)).setImageDrawable(appIcon); ((TextView) appSnippet.findViewById(R.id.app_name)).setText(appLabel); TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup();/*from w ww .ja va2s. com*/ ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager); adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { } }); boolean permVisible = false; mScrollView = null; mOkCanInstall = false; int msg = 0; if (mAppDiff.mPkgInfo != null) { AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo); final int NP = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL); final int ND = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE); if (mAppDiff.mInstalledAppInfo != null) { msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system : R.string.install_confirm_update; mScrollView = new CaffeinatedScrollView(this); mScrollView.setFillViewport(true); final boolean newPermissionsFound = (perms .getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0); if (newPermissionsFound) { permVisible = true; mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW)); } else { throw new RuntimeException( "This should not happen. No new permissions were found but InstallConfirmActivity has been started!"); } adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView); } else { findViewById(R.id.tabscontainer).setVisibility(View.GONE); findViewById(R.id.divider).setVisibility(View.VISIBLE); } if (NP > 0 || ND > 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); } final ViewGroup privacyList = (ViewGroup) root.findViewById(R.id.privacylist); if (NP > 0) { privacyList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_PERSONAL)); } else { privacyList.setVisibility(View.GONE); } final ViewGroup deviceList = (ViewGroup) root.findViewById(R.id.devicelist); if (ND > 0) { deviceList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_DEVICE)); } else { root.findViewById(R.id.devicelist).setVisibility(View.GONE); } adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root); } } if (!permVisible) { if (mAppDiff.mInstalledAppInfo != null) { // This is an update to an application, but there are no // permissions at all. msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system_no_perms : R.string.install_confirm_update_no_perms; } else { // This is a new application with no permissions. msg = R.string.install_confirm_no_perms; } tabHost.setVisibility(View.GONE); findViewById(R.id.filler).setVisibility(View.VISIBLE); findViewById(R.id.divider).setVisibility(View.GONE); mScrollView = null; } if (msg != 0) { ((TextView) findViewById(R.id.install_confirm)).setText(msg); } mInstallConfirm.setVisibility(View.VISIBLE); mOk = (Button) findViewById(R.id.ok_button); mCancel = (Button) findViewById(R.id.cancel_button); mOk.setOnClickListener(this); mCancel.setOnClickListener(this); if (mScrollView == null) { // There is nothing to scroll view, so the ok button is immediately // set to install. mOk.setText(R.string.menu_install); mOkCanInstall = true; } else { mScrollView.setFullScrollAction(new Runnable() { @Override public void run() { mOk.setText(R.string.menu_install); mOkCanInstall = true; } }); } }
From source file:com.jtechme.apphub.privileged.views.InstallConfirmActivity.java
private void startInstallConfirm() { final Drawable appIcon = mAppDiff.mPkgInfo.applicationInfo.loadIcon(mPm); final String appLabel = (String) mAppDiff.mPkgInfo.applicationInfo.loadLabel(mPm); View appSnippet = findViewById(R.id.app_snippet); ((ImageView) appSnippet.findViewById(R.id.app_icon)).setImageDrawable(appIcon); ((TextView) appSnippet.findViewById(R.id.app_name)).setText(appLabel); TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup();/* ww w .j a v a 2s . c om*/ ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager); adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { } }); boolean permVisible = false; mScrollView = null; mOkCanInstall = false; int msg = 0; AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo); if (mAppDiff.mInstalledAppInfo != null) { msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system : R.string.install_confirm_update; mScrollView = new CaffeinatedScrollView(this); mScrollView.setFillViewport(true); final boolean newPermissionsFound = perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0; if (newPermissionsFound) { permVisible = true; mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW)); } else { throw new RuntimeException( "This should not happen. No new permissions were found but InstallConfirmActivity has been started!"); } adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView); } else { findViewById(R.id.tabscontainer).setVisibility(View.GONE); findViewById(R.id.divider).setVisibility(View.VISIBLE); } final int np = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL); final int nd = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE); if (np > 0 || nd > 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); } final ViewGroup privacyList = (ViewGroup) root.findViewById(R.id.privacylist); if (np > 0) { privacyList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_PERSONAL)); } else { privacyList.setVisibility(View.GONE); } final ViewGroup deviceList = (ViewGroup) root.findViewById(R.id.devicelist); if (nd > 0) { deviceList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_DEVICE)); } else { root.findViewById(R.id.devicelist).setVisibility(View.GONE); } adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root); } if (!permVisible) { if (mAppDiff.mInstalledAppInfo != null) { // This is an update to an application, but there are no // permissions at all. msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system_no_perms : R.string.install_confirm_update_no_perms; } else { // This is a new application with no permissions. msg = R.string.install_confirm_no_perms; } tabHost.setVisibility(View.GONE); findViewById(R.id.filler).setVisibility(View.VISIBLE); findViewById(R.id.divider).setVisibility(View.GONE); mScrollView = null; } if (msg != 0) { ((TextView) findViewById(R.id.install_confirm)).setText(msg); } mInstallConfirm.setVisibility(View.VISIBLE); mOk = (Button) findViewById(R.id.ok_button); mCancel = (Button) findViewById(R.id.cancel_button); mOk.setOnClickListener(this); mCancel.setOnClickListener(this); if (mScrollView == null) { // There is nothing to scroll view, so the ok button is immediately // set to install. mOk.setText(R.string.menu_install); mOkCanInstall = true; } else { mScrollView.setFullScrollAction(new Runnable() { @Override public void run() { mOk.setText(R.string.menu_install); mOkCanInstall = true; } }); } }
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 av a2 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; } }); } }