Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Update permissions UI
Browse files Browse the repository at this point in the history
 - Update existing settings page to show action bar and app header.
 - Add page to manage apps based on permission.

Change-Id: I2211044fbe4db4b4fbf981f1a7ad7a01666cd69d
  • Loading branch information
Monkopedia committed Mar 27, 2015
1 parent 024f373 commit 46c5510
Show file tree
Hide file tree
Showing 14 changed files with 675 additions and 35 deletions.
3 changes: 3 additions & 0 deletions AndroidManifest.xml
Expand Up @@ -75,9 +75,12 @@
<activity android:name=".permission.ManagePermissionsActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true"
android:label="@string/app_permissions"
android:theme="@android:style/Theme.Material.Settings"
android:permission="android.permission.GRANT_REVOKE_PERMISSIONS">
<intent-filter>
<action android:name="android.intent.action.MANAGE_APP_PERMISSIONS" />
<action android:name="android.intent.action.MANAGE_PERMISSION_APPS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Expand Down
21 changes: 21 additions & 0 deletions res/drawable/header_background.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item android:drawable="@color/header_background_color" />
</ripple>

27 changes: 27 additions & 0 deletions res/drawable/ic_info.xml
@@ -0,0 +1,27 @@
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M0 0h24v24H0z"
android:fillColor="#00000000"/>
<path
android:fillColor="#FFFFFFFF"
android:pathData="M11.0,17.0l2.0,0.0l0.0,-6.0l-2.0,0.0l0.0,6.0zm1.0,-15.0C6.48,2.0 2.0,6.48 2.0,12.0s4.48,10.0 10.0,10.0 10.0,-4.48 10.0,-10.0S17.52,2.0 12.0,2.0zm0.0,18.0c-4.41,0.0 -8.0,-3.59 -8.0,-8.0s3.59,-8.0 8.0,-8.0 8.0,3.59 8.0,8.0 -3.59,8.0 -8.0,8.0zM11.0,9.0l2.0,0.0L13.0,7.0l-2.0,0.0l0.0,2.0z"/>
</vector>
62 changes: 62 additions & 0 deletions res/layout/header.xml
@@ -0,0 +1,62 @@
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@drawable/header_background"
android:gravity="center_vertical"
android:theme="@style/Theme.Header.Settings" >

<ImageView android:id="@+id/icon"
android:layout_width="@dimen/header_subsettings_margin_start"
android:layout_height="40dp"
android:gravity="end"
android:layout_centerVertical="true" />

<TextView
android:id="@+id/name"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_toStartOf="@+id/app_settings"
android:layout_marginStart="@dimen/header_subsettings_margin_start"
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textColor="@android:color/white"
android:textAlignment="viewStart" />

<ImageView
android:id="@+id/info"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="@dimen/header_subsettings_margin_end"
android:layout_centerVertical="true"
android:minHeight="0dp"
android:minWidth="0dp"
android:scaleType="center"
android:src="@drawable/ic_info"
style="?android:attr/borderlessButtonStyle" />

<View
android:id="@+id/row_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/listDivider" />

</RelativeLayout>

1 change: 1 addition & 0 deletions res/values/colors.xml
Expand Up @@ -17,5 +17,6 @@
<resources>
<color name="shadow">#cc222222</color>
<color name="transparent">#00000000</color>
<color name="header_background_color">#ff37474f</color>
</resources>

25 changes: 25 additions & 0 deletions res/values/dimens.xml
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<resources>
<!-- Header sub settings margin start / end -->
<dimen name="header_subsettings_margin_start">72dp</dimen>
<dimen name="header_subsettings_margin_end">16dp</dimen>

<!-- Header margin start / end -->
<dimen name="header_margin_start">16dp</dimen>
<dimen name="header_margin_end">16dp</dimen>
</resources>
3 changes: 3 additions & 0 deletions res/values/strings.xml
Expand Up @@ -197,4 +197,7 @@
<string name="permdesc_togglePermissions" translatable="false">Allows the holder to launch
the UI for toggling app permissions. Should never be needed for normal apps.</string>

<!-- Title for page of managing application permissions -->
<string name="app_permissions">App permissions</string>

</resources>
3 changes: 3 additions & 0 deletions res/values/styles.xml
Expand Up @@ -23,4 +23,7 @@
<style name="Theme.AlertDialogActivity" parent="@android:style/Theme.DeviceDefault.Light.Panel">
<item name="android:backgroundDimEnabled">true</item>
</style>

<style name="Theme.Header.Settings" parent="@android:style/Theme.Material.Settings">
</style>
</resources>
Expand Up @@ -289,5 +289,9 @@ public String getName() {
public boolean isGranted() {
return mGranted;
}

public void setGranted(boolean granted) {
mGranted = granted;
}
}
}
Expand Up @@ -17,6 +17,7 @@
package com.android.packageinstaller.permission;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
Expand All @@ -28,14 +29,30 @@ public final class ManagePermissionsActivity extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

String packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME);
if (packageName == null) {
Log.i(LOG_TAG, "Missing mandatory argument ARG_PACKAGE_NAME");
Fragment fragment = null;
String action = getIntent().getAction();
if (Intent.ACTION_MANAGE_APP_PERMISSIONS.equals(action)) {
String packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME);
if (packageName == null) {
Log.i(LOG_TAG, "Missing mandatory argument EXTRA_PACKAGE_NAME");
finish();
return;
}
fragment = ManagePermissionsFragment.newInstance(packageName);
} else if (Intent.ACTION_MANAGE_PERMISSION_APPS.equals(action)) {
String permissionName = getIntent().getStringExtra(Intent.EXTRA_PERMISSION_NAME);
if (permissionName == null) {
Log.i(LOG_TAG, "Missing mandatory argument EXTRA_PERMISSION_NAME");
finish();
return;
}
fragment = PermissionManagementFragment.newInstance(permissionName);
} else {
Log.w(LOG_TAG, "Unrecognized action " + action);
finish();
return;
}

ManagePermissionsFragment fragment = ManagePermissionsFragment.newInstance(packageName);
getFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
}
}
Expand Up @@ -16,17 +16,24 @@

package com.android.packageinstaller.permission;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;

public final class ManagePermissionsFragment extends PreferenceFragment {
import com.android.packageinstaller.R;

public final class ManagePermissionsFragment extends SettingsWithHeader
implements OnPreferenceChangeListener {
private static final String LOG_TAG = "ManagePermissionsFragment";

private AppPermissions mAppPermissions;
Expand All @@ -42,6 +49,8 @@ public static ManagePermissionsFragment newInstance(String packageName) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
bindUi();
}

Expand All @@ -51,45 +60,38 @@ public void onResume() {
updateUi();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
getActivity().finish();
return true;
}
return super.onOptionsItemSelected(item);
}

private void bindUi() {
String packageName = getArguments().getString(Intent.EXTRA_PACKAGE_NAME);

final PackageInfo packageInfo = getPackageInfo(packageName);
final Activity activity = getActivity();
PackageInfo packageInfo = getPackageInfo(packageName);
if (packageInfo == null) {
getActivity().finish();
Toast.makeText(activity, R.string.app_not_found_dlg_title, Toast.LENGTH_LONG)
.show();
activity.finish();
return;
}
final PackageManager pm = activity.getPackageManager();
ApplicationInfo appInfo = packageInfo.applicationInfo;
setHeader(appInfo.loadIcon(pm), appInfo.loadLabel(pm), null);

PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getActivity());
mAppPermissions = new AppPermissions(getActivity(),
packageInfo, null);

Preference.OnPreferenceChangeListener changeListener =
new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String groupName = preference.getKey();
AppPermissions.PermissionGroup group = mAppPermissions
.getPermissionGroup(groupName);

if (group == null) {
return false;
}

if (newValue == Boolean.TRUE) {
group.grantRuntimePermissions();
} else {
group.revokeRuntimePermissions();
}

return true;
}
};
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(activity);
mAppPermissions = new AppPermissions(activity, packageInfo, null);

for (AppPermissions.PermissionGroup group : mAppPermissions.getPermissionGroups()) {
if (group.hasRuntimePermissions()) {
SwitchPreference preference = new SwitchPreference(getActivity());
preference.setOnPreferenceChangeListener(changeListener);
SwitchPreference preference = new SwitchPreference(activity);
preference.setOnPreferenceChangeListener(this);
preference.setKey(group.getName());
preference.setIcon(group.getIconResId());
preference.setTitle(group.getLabel());
Expand All @@ -101,6 +103,24 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
setPreferenceScreen(screen);
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String groupName = preference.getKey();
AppPermissions.PermissionGroup group = mAppPermissions.getPermissionGroup(groupName);

if (group == null) {
return false;
}

if (newValue == Boolean.TRUE) {
group.grantRuntimePermissions();
} else {
group.revokeRuntimePermissions();
}

return true;
}

private void updateUi() {
mAppPermissions.refresh();

Expand Down

0 comments on commit 46c5510

Please sign in to comment.