Skip to content

Commit 5e4381c

Browse files
author
Irina Dumitrescu
committed
In app permissions, when selecting an app to view its permissions from
the drop down, display a text message if there is no permission to show. Bug:24800054 Test: adb install ./out/gradle/TestDPC/build/outputs/apk/normal/debug/TestDPC-normal-debug.apk Change-Id: I077575d0692f98f23050c24b006057014e79f403
1 parent b8a9c3c commit 5e4381c

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

app/src/main/java/com/afwsamples/testdpc/common/BaseManageComponentFragment.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,15 @@ public void onNothingSelected(AdapterView<?> parent) {
8181
view.findViewById(R.id.reset_app).setOnClickListener(this);
8282
view.findViewById(R.id.add_new_row).setOnClickListener(this);
8383
view.findViewById(R.id.load_default_button).setOnClickListener(this);
84-
onSpinnerItemSelected((T) mManagedAppsSpinner.getSelectedItem());
8584
return view;
8685
}
8786

87+
@Override
88+
public void onActivityCreated(Bundle savedInstanceState) {
89+
super.onActivityCreated(savedInstanceState);
90+
onSpinnerItemSelected((T) mManagedAppsSpinner.getSelectedItem());
91+
}
92+
8893
protected abstract SpinnerAdapter createSpinnerAdapter();
8994

9095
protected abstract BaseAdapter createListAdapter();

app/src/main/java/com/afwsamples/testdpc/profilepolicy/permission/ManageAppPermissionsFragment.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
import android.view.ViewGroup;
3333
import android.widget.BaseAdapter;
3434

35+
import android.widget.TextView;
3536
import com.afwsamples.testdpc.DeviceAdminReceiver;
3637
import com.afwsamples.testdpc.R;
37-
import com.afwsamples.testdpc.common.BaseManageComponentFragment;
3838
import com.afwsamples.testdpc.common.ManageAppFragment;
3939

4040
import java.util.ArrayList;
@@ -50,6 +50,7 @@ public class ManageAppPermissionsFragment extends ManageAppFragment {
5050

5151
private DevicePolicyManager mDpm;
5252
private List<AppPermissionsArrayAdapter.AppPermission> mAppPermissions = new ArrayList<>();
53+
private TextView mAppPermissionsView;
5354

5455
@Override
5556
public void onCreate(Bundle savedInstanceState) {
@@ -64,6 +65,8 @@ public View onCreateView(LayoutInflater layoutInflater, ViewGroup container,
6465
view.findViewById(R.id.load_default_button).setVisibility(View.GONE);
6566
view.findViewById(R.id.add_new_row).setVisibility(View.GONE);
6667
view.findViewById(R.id.manage_app_button_container).setVisibility(View.GONE);
68+
mAppPermissionsView = view.findViewById(R.id.error_message);
69+
mAppPermissionsView.setText(R.string.app_permissions_empty);
6770
return view;
6871
}
6972

@@ -107,8 +110,7 @@ protected void onSpinnerItemSelected(ApplicationInfo appInfo) {
107110
permissionState);
108111
populatedPermissions.add(populatedPerm);
109112
}
110-
111-
loadAppPermissionsList(populatedPermissions);
113+
displayAppPermissions(populatedPermissions);
112114
}
113115
}
114116

@@ -129,12 +131,19 @@ protected BaseAdapter createListAdapter() {
129131
return new AppPermissionsArrayAdapter(getActivity(), 0, mAppPermissions);
130132
}
131133

132-
private void loadAppPermissionsList(
133-
List<AppPermissionsArrayAdapter.AppPermission> permissions) {
134-
if (permissions != null) {
135-
mAppPermissions.clear();
134+
/**
135+
* Displays the list of permissions for the selected app. If there are no permissions to
136+
* be displayed, a text view displays a message about this.
137+
*/
138+
private void displayAppPermissions(
139+
List<AppPermissionsArrayAdapter.AppPermission> permissions) {
140+
mAppPermissions.clear();
141+
if (permissions.isEmpty()) {
142+
mAppPermissionsView.setVisibility(View.VISIBLE);
143+
} else {
144+
mAppPermissionsView.setVisibility(View.GONE);
136145
mAppPermissions.addAll(permissions);
137-
mAdapter.notifyDataSetChanged();
138146
}
147+
mAdapter.notifyDataSetChanged();
139148
}
140149
}

app/src/main/res/layout/manage_apps.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ limitations under the License.
5050
android:layout_alignParentRight="true"
5151
android:text="@string/plus" />
5252

53+
<TextView
54+
android:id="@+id/error_message"
55+
android:layout_below="@id/header_view"
56+
android:layout_above="@+id/load_default_button"
57+
android:visibility="gone"
58+
android:layout_height="wrap_content"
59+
android:layout_width="match_parent"
60+
android:paddingTop="16dp"
61+
android:paddingBottom="4dp" />
62+
5363
<ListView
5464
android:id="@+id/app_list_view"
5565
android:layout_below="@id/header_view"

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,8 @@
797797
<string name="permission_default">Let user decide</string>
798798
<string name="permission_deny">Deny</string>
799799
<string name="manage_app_permissions">Manage app permissions</string>
800+
<!-- Message displayed when there are no apps permissions to show. -->
801+
<string name="app_permissions_empty">There are no permissions to display for this app.</string>
800802

801803
<!-- Keyguard features -->
802804
<string name="keyguard_features">Keyguard features</string>

0 commit comments

Comments
 (0)