OSDN Git Service

Move the logs and settings into a separate database, to prevent database locks by...
[android-x86/external-koush-Superuser.git] / Superuser / src / com / koushikdutta / superuser / db / UidCommand.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.db;
18
19 import android.content.Context;
20 import android.content.pm.PackageInfo;
21 import android.content.pm.PackageManager;
22 import android.database.Cursor;
23
24
25 public class UidCommand {
26     public String username;
27     public String name;
28     public String packageName;
29     public int uid;
30     public String command;
31     public int desiredUid;
32     public String desiredName;
33     
34     public String getName() {
35         if (name != null)
36             return name;
37         if (packageName != null)
38             return packageName;
39         if (username != null && username.length() > 0)
40             return username;
41         return String.valueOf(uid);
42     }
43     
44     
45     public void getPackageInfo(Context context) {
46         try {
47             PackageManager pm = context.getPackageManager();
48             PackageInfo pi = context.getPackageManager().getPackageInfo(pm.getPackagesForUid(uid)[0], 0);
49             name = pi.applicationInfo.loadLabel(pm).toString();
50             packageName = pi.packageName;
51         }
52         catch (Exception ex) {
53         }
54     }
55
56     public void getUidCommand(Cursor c) {
57         uid = c.getInt(c.getColumnIndex("uid"));
58         command = c.getString(c.getColumnIndex("command"));
59         name = c.getString(c.getColumnIndex("name"));
60         packageName = c.getString(c.getColumnIndex("package_name"));
61         desiredUid = c.getInt(c.getColumnIndex("desired_uid"));
62         desiredName = c.getString(c.getColumnIndex("desired_name"));
63         username = c.getString(c.getColumnIndex("username"));
64     }
65 }