Skip to content

Commit 1aaa8c1

Browse files
committed
Add get/setTrustAgentConfiguration api in testdpc
1. Add a page in lock restriction that showing trust agent config just like app restriction. 2. Create BaseManageComponentFragment based ManageAppFragment for us to configure service (trustagent) rather than app. TODO: getTrustAgentConfiguration(null, trustAgent) is still not yet supported in TestDPC. It is supposed to return a aggregated list of Bundle in a read only UI. Bug: 28012233 Change-Id: I9276f7ecc48fac5a758a6f5aba0fbfc9ca258a54
1 parent a8bdc46 commit 1aaa8c1

13 files changed

+713
-112
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.afwsamples.testdpc.common;
18+
19+
import android.app.Fragment;
20+
import android.content.pm.PackageManager;
21+
import android.os.Bundle;
22+
import android.view.LayoutInflater;
23+
import android.view.View;
24+
import android.view.ViewGroup;
25+
import android.widget.AdapterView;
26+
import android.widget.BaseAdapter;
27+
import android.widget.ListView;
28+
import android.widget.Spinner;
29+
import android.widget.SpinnerAdapter;
30+
import android.widget.TextView;
31+
32+
import com.afwsamples.testdpc.R;
33+
34+
/**
35+
* This fragment shows a spinner of all allowed component and a list of associated properties.
36+
*/
37+
public abstract class BaseManageComponentFragment<T> extends Fragment
38+
implements View.OnClickListener {
39+
40+
protected PackageManager mPackageManager;
41+
protected Spinner mManagedAppsSpinner;
42+
protected TextView mHeaderView;
43+
protected ListView mAppListView;
44+
protected BaseAdapter mAdapter;
45+
46+
@Override
47+
public void onResume() {
48+
super.onResume();
49+
getActivity().getActionBar().setTitle(R.string.manage_apps);
50+
}
51+
52+
@Override
53+
public void onCreate(Bundle savedInstanceState) {
54+
super.onCreate(savedInstanceState);
55+
mPackageManager = getActivity().getPackageManager();
56+
}
57+
58+
@Override
59+
public View onCreateView(LayoutInflater layoutInflater, ViewGroup container,
60+
Bundle savedInstanceState) {
61+
View view = layoutInflater.inflate(R.layout.manage_apps, null);
62+
63+
mHeaderView = (TextView) view.findViewById(R.id.header_text);
64+
mManagedAppsSpinner = (Spinner) view.findViewById(R.id.managed_apps_list);
65+
mManagedAppsSpinner.setAdapter(createSpinnerAdapter());
66+
mManagedAppsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
67+
@Override
68+
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
69+
onSpinnerItemSelected((T) mManagedAppsSpinner.getSelectedItem());
70+
}
71+
72+
@Override
73+
public void onNothingSelected(AdapterView<?> parent) {
74+
// Do nothing.
75+
}
76+
});
77+
mAppListView = (ListView) view.findViewById(R.id.app_list_view);
78+
mAdapter = createListAdapter();
79+
mAppListView.setAdapter(mAdapter);
80+
view.findViewById(R.id.save_app).setOnClickListener(this);
81+
view.findViewById(R.id.reset_app).setOnClickListener(this);
82+
view.findViewById(R.id.add_new_row).setOnClickListener(this);
83+
view.findViewById(R.id.load_default_button).setOnClickListener(this);
84+
onSpinnerItemSelected((T) mManagedAppsSpinner.getSelectedItem());
85+
return view;
86+
}
87+
88+
protected abstract SpinnerAdapter createSpinnerAdapter();
89+
90+
protected abstract BaseAdapter createListAdapter();
91+
92+
/**
93+
* Populates the adapter for app_list_view with data for this application.
94+
* @param item the selected spinner item.
95+
*/
96+
protected abstract void onSpinnerItemSelected(T item);
97+
98+
@Override
99+
public void onClick(View view) {
100+
switch (view.getId()) {
101+
case R.id.reset_app:
102+
resetConfig();
103+
break;
104+
case R.id.save_app:
105+
saveConfig();
106+
break;
107+
case R.id.add_new_row:
108+
addNewRow();
109+
break;
110+
case R.id.load_default_button:
111+
loadDefault();
112+
}
113+
}
114+
115+
protected abstract void resetConfig();
116+
protected abstract void saveConfig();
117+
protected abstract void addNewRow();
118+
protected abstract void loadDefault();
119+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.afwsamples.testdpc.common;
18+
19+
import android.annotation.TargetApi;
20+
import android.os.Build;
21+
import android.os.Bundle;
22+
import android.os.PersistableBundle;
23+
24+
import java.util.Set;
25+
26+
public class BundleUtil {
27+
28+
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
29+
public static PersistableBundle bundleToPersistableBundle(Bundle bundle) {
30+
Set<String> keySet = bundle.keySet();
31+
PersistableBundle persistableBundle = new PersistableBundle();
32+
for (String key : keySet) {
33+
Object value = bundle.get(key);
34+
if (value instanceof Boolean) {
35+
persistableBundle.putBoolean(key, (boolean) value);
36+
} else if (value instanceof Integer) {
37+
persistableBundle.putInt(key, (int) value);
38+
} else if (value instanceof String) {
39+
persistableBundle.putString(key, (String) value);
40+
} else if (value instanceof String[]) {
41+
persistableBundle.putStringArray(key, (String[]) value);
42+
} else if (value instanceof Bundle) {
43+
PersistableBundle innerBundle = bundleToPersistableBundle((Bundle) value);
44+
persistableBundle.putPersistableBundle(key, innerBundle);
45+
}
46+
}
47+
return persistableBundle;
48+
}
49+
50+
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
51+
public static Bundle persistableBundleToBundle(PersistableBundle persistableBundle) {
52+
Set<String> keySet = persistableBundle.keySet();
53+
Bundle bundle = new Bundle();
54+
for (String key : keySet) {
55+
Object value = persistableBundle.get(key);
56+
if (value instanceof Boolean) {
57+
bundle.putBoolean(key, (boolean) value);
58+
} else if (value instanceof Integer) {
59+
bundle.putInt(key, (int) value);
60+
} else if (value instanceof String) {
61+
bundle.putString(key, (String) value);
62+
} else if (value instanceof String[]) {
63+
bundle.putStringArray(key, (String[]) value);
64+
} else if (value instanceof PersistableBundle) {
65+
Bundle innerBundle = persistableBundleToBundle((PersistableBundle) value);
66+
bundle.putBundle(key, innerBundle);
67+
}
68+
}
69+
return bundle;
70+
}
71+
}
Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2015 The Android Open Source Project
2+
* Copyright (C) 2016 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,80 +16,26 @@
1616

1717
package com.afwsamples.testdpc.common;
1818

19-
import android.app.Fragment;
2019
import android.content.pm.ApplicationInfo;
21-
import android.content.pm.PackageManager;
22-
import android.os.Bundle;
23-
import android.view.LayoutInflater;
24-
import android.view.View;
25-
import android.view.ViewGroup;
26-
import android.widget.AdapterView;
27-
import android.widget.ListView;
28-
import android.widget.Spinner;
29-
import android.widget.TextView;
20+
import android.widget.SpinnerAdapter;
3021

3122
import com.afwsamples.testdpc.R;
3223

3324
import java.util.ArrayList;
3425
import java.util.Collections;
3526
import java.util.List;
3627

37-
/**
38-
* This fragment shows a spinner of all allowed apps and a list of properties associated with the
39-
* currently selected application.
40-
*/
41-
public abstract class ManageAppFragment extends Fragment implements View.OnClickListener {
42-
43-
protected PackageManager mPackageManager;
44-
protected Spinner mManagedAppsSpinner;
45-
protected TextView mHeaderView;
46-
protected ListView mAppListView;
47-
48-
@Override
49-
public void onResume() {
50-
super.onResume();
51-
getActivity().getActionBar().setTitle(R.string.manage_apps);
52-
}
53-
28+
public abstract class ManageAppFragment extends BaseManageComponentFragment<ApplicationInfo> {
5429
@Override
55-
public void onCreate(Bundle savedInstanceState) {
56-
super.onCreate(savedInstanceState);
57-
mPackageManager = getActivity().getPackageManager();
58-
}
59-
60-
@Override
61-
public View onCreateView(LayoutInflater layoutInflater, ViewGroup container,
62-
Bundle savedInstanceState) {
63-
View view = layoutInflater.inflate(R.layout.manage_apps, null);
64-
30+
protected SpinnerAdapter createSpinnerAdapter() {
6531
List<ApplicationInfo> managedAppList = getInstalledLaunchableApps();
6632
Collections.sort(managedAppList,
6733
new ApplicationInfo.DisplayNameComparator(mPackageManager));
68-
AppInfoSpinnerAdapter appInfoSpinnerAdapter = new AppInfoSpinnerAdapter(getActivity(),
69-
R.layout.app_row, R.id.pkg_name, managedAppList);
70-
mHeaderView = (TextView) view.findViewById(R.id.header_text);
71-
mManagedAppsSpinner = (Spinner) view.findViewById(R.id.managed_apps_list);
72-
mManagedAppsSpinner.setAdapter(appInfoSpinnerAdapter);
73-
mManagedAppsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
74-
@Override
75-
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
76-
loadData(((ApplicationInfo) mManagedAppsSpinner.getSelectedItem()).packageName);
77-
}
78-
79-
@Override
80-
public void onNothingSelected(AdapterView<?> parent) {
81-
// Do nothing.
82-
}
83-
});
84-
mAppListView = (ListView) view.findViewById(R.id.app_list_view);
85-
view.findViewById(R.id.save_app).setOnClickListener(this);
86-
view.findViewById(R.id.reset_app).setOnClickListener(this);
87-
view.findViewById(R.id.add_new_row).setOnClickListener(this);
88-
view.findViewById(R.id.load_default_button).setOnClickListener(this);
89-
loadData(((ApplicationInfo) mManagedAppsSpinner.getSelectedItem()).packageName);
90-
return view;
34+
return new AppInfoSpinnerAdapter(getActivity(), R.layout.app_row, R.id.pkg_name,
35+
managedAppList);
9136
}
9237

38+
9339
private List<ApplicationInfo> getInstalledLaunchableApps() {
9440
List<ApplicationInfo> managedAppList = mPackageManager.getInstalledApplications(
9541
0 /* Default flags */);
@@ -101,32 +47,4 @@ private List<ApplicationInfo> getInstalledLaunchableApps() {
10147
}
10248
return launchableAppList;
10349
}
104-
105-
/**
106-
* Populates the adapter for app_list_view with data for this application.
107-
* @param pkgName The package for which to load information
108-
*/
109-
protected abstract void loadData(String pkgName);
110-
111-
@Override
112-
public void onClick(View view) {
113-
switch (view.getId()) {
114-
case R.id.reset_app:
115-
resetConfig();
116-
break;
117-
case R.id.save_app:
118-
saveConfig();
119-
break;
120-
case R.id.add_new_row:
121-
addNewRow();
122-
break;
123-
case R.id.load_default_button:
124-
loadDefault();
125-
}
126-
}
127-
128-
protected abstract void resetConfig();
129-
protected abstract void saveConfig();
130-
protected abstract void addNewRow();
131-
protected abstract void loadDefault();
13250
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.afwsamples.testdpc.common;
18+
19+
import android.app.Fragment;
20+
import android.content.ComponentName;
21+
import android.content.pm.ApplicationInfo;
22+
import android.content.pm.PackageManager;
23+
import android.content.pm.ResolveInfo;
24+
import android.os.Bundle;
25+
import android.view.LayoutInflater;
26+
import android.view.View;
27+
import android.view.ViewGroup;
28+
import android.widget.AdapterView;
29+
import android.widget.ListView;
30+
import android.widget.Spinner;
31+
import android.widget.SpinnerAdapter;
32+
33+
import com.afwsamples.testdpc.R;
34+
35+
import java.util.ArrayList;
36+
import java.util.Collections;
37+
import java.util.List;
38+
39+
/**
40+
* This fragment shows a spinner of all allowed apps and a list of properties associated with the
41+
* currently selected application.
42+
*/
43+
public abstract class ManageResolveInfoFragment extends BaseManageComponentFragment<ResolveInfo> {
44+
45+
protected List<ResolveInfo> mResolveInfos;
46+
47+
@Override
48+
public void onCreate(Bundle savedInstanceState) {
49+
super.onCreate(savedInstanceState);
50+
}
51+
52+
@Override
53+
protected SpinnerAdapter createSpinnerAdapter() {
54+
mResolveInfos = loadResolveInfoList();
55+
return new ResolveInfoSpinnerAdapter(
56+
getActivity(), R.layout.app_row, R.id.pkg_name, mResolveInfos);
57+
}
58+
59+
protected abstract List<ResolveInfo> loadResolveInfoList();
60+
}

0 commit comments

Comments
 (0)