OSDN Git Service

LICENSE
[android-x86/external-koush-Superuser.git] / Superuser / src / com / koushikdutta / superuser / NotifyActivity.java
1 /*
2  * Copyright (C) 2013 Koushik Dutta (@koush)
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.koushikdutta.superuser;
18
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.content.pm.PackageInfo;
22 import android.content.pm.PackageManager;
23 import android.os.Bundle;
24 import android.view.View;
25 import android.view.View.OnClickListener;
26 import android.widget.ImageView;
27 import android.widget.TextView;
28
29 public class NotifyActivity extends Activity {
30     @Override
31     protected void onCreate(Bundle savedInstanceState) {
32         super.onCreate(savedInstanceState);
33         
34         setContentView(R.layout.notify);
35         
36         Intent intent = getIntent();
37         if (intent == null) {
38             finish();
39             return;
40         }
41         int callerUid = intent.getIntExtra("caller_uid", -1);
42         if (callerUid == -1) {
43             finish();
44             return;
45         }
46         
47         final View packageInfo = findViewById(R.id.packageinfo);
48         final PackageManager pm = getPackageManager();
49         String[] pkgs = pm.getPackagesForUid(callerUid);
50         TextView unknown = (TextView)findViewById(R.id.unknown);
51         unknown.setText(getString(R.string.unknown_uid, callerUid));
52
53         if (pkgs != null && pkgs.length > 0) {
54             for (String pkg: pkgs) {
55                 try {
56                     PackageInfo pi = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS);
57                     ((TextView)findViewById(R.id.request)).setText(getString(R.string.application_request, pi.applicationInfo.loadLabel(pm)));
58                     ImageView icon = (ImageView)packageInfo.findViewById(R.id.image);
59                     icon.setImageDrawable(pi.applicationInfo.loadIcon(pm));
60                     ((TextView)packageInfo.findViewById(R.id.title)).setText(pi.applicationInfo.loadLabel(pm));
61                     
62                     ((TextView)findViewById(R.id.app_header)).setText(pi.applicationInfo.loadLabel(pm));
63                     ((TextView)findViewById(R.id.package_header)).setText(pi.packageName);
64                     
65                     // could display them all, but screw it...
66                     // maybe a better ux for this later
67                     break;
68                 }
69                 catch (Exception ex) {
70                 }
71             }
72             findViewById(R.id.unknown).setVisibility(View.GONE);
73         }
74         
75         findViewById(R.id.ok).setOnClickListener(new OnClickListener() {
76             @Override
77             public void onClick(View v) {
78                 finish();
79             }
80         });
81     }
82 }