blob: 302face14c1a7c58e70523526e4ac0e247fd1746 [file] [log] [blame]
Jason Monke8f8be72018-01-21 10:10:35 -05001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui;
16
17import android.app.Activity;
18import android.app.AlertDialog;
19import android.app.slice.SliceManager;
20import android.app.slice.SliceProvider;
21import android.content.DialogInterface;
22import android.content.DialogInterface.OnClickListener;
23import android.content.DialogInterface.OnDismissListener;
24import android.content.pm.PackageManager;
25import android.content.pm.PackageManager.NameNotFoundException;
26import android.net.Uri;
27import android.os.Bundle;
28import android.util.Log;
29import android.widget.CheckBox;
30import android.widget.TextView;
31
32public class SlicePermissionActivity extends Activity implements OnClickListener,
33 OnDismissListener {
34
35 private static final String TAG = "SlicePermissionActivity";
36
37 private CheckBox mAllCheckbox;
38
39 private Uri mUri;
40 private String mCallingPkg;
41 private String mProviderPkg;
42
43 @Override
44 protected void onCreate(Bundle savedInstanceState) {
45 super.onCreate(savedInstanceState);
46
47 mUri = getIntent().getParcelableExtra(SliceProvider.EXTRA_BIND_URI);
48 mCallingPkg = getIntent().getStringExtra(SliceProvider.EXTRA_PKG);
49 mProviderPkg = getIntent().getStringExtra(SliceProvider.EXTRA_PROVIDER_PKG);
50
51 try {
52 PackageManager pm = getPackageManager();
53 CharSequence app1 = pm.getApplicationInfo(mCallingPkg, 0).loadLabel(pm);
54 CharSequence app2 = pm.getApplicationInfo(mProviderPkg, 0).loadLabel(pm);
55 AlertDialog dialog = new AlertDialog.Builder(this)
56 .setTitle(getString(R.string.slice_permission_title, app1, app2))
57 .setView(R.layout.slice_permission_request)
58 .setNegativeButton(R.string.slice_permission_deny, this)
59 .setPositiveButton(R.string.slice_permission_allow, this)
60 .setOnDismissListener(this)
61 .show();
62 TextView t1 = dialog.getWindow().getDecorView().findViewById(R.id.text1);
63 t1.setText(getString(R.string.slice_permission_text_1, app2));
64 TextView t2 = dialog.getWindow().getDecorView().findViewById(R.id.text2);
65 t2.setText(getString(R.string.slice_permission_text_2, app2));
66 mAllCheckbox = dialog.getWindow().getDecorView().findViewById(
67 R.id.slice_permission_checkbox);
68 mAllCheckbox.setText(getString(R.string.slice_permission_checkbox, app1));
69 } catch (NameNotFoundException e) {
70 Log.e(TAG, "Couldn't find package", e);
71 finish();
72 }
73 }
74
75 @Override
76 public void onClick(DialogInterface dialog, int which) {
77 if (which == DialogInterface.BUTTON_POSITIVE) {
78 getSystemService(SliceManager.class).grantPermissionFromUser(mUri, mCallingPkg,
79 mAllCheckbox.isChecked());
80 }
81 finish();
82 }
83
84 @Override
85 public void onDismiss(DialogInterface dialog) {
86 finish();
87 }
88}