You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
refactor source tree organization, switch to meson
This commit is contained in:
587
src/api-impl/android/content/pm/ActivityInfo.java
Normal file
587
src/api-impl/android/content/pm/ActivityInfo.java
Normal file
File diff suppressed because it is too large
Load Diff
656
src/api-impl/android/content/pm/ApplicationInfo.java
Normal file
656
src/api-impl/android/content/pm/ApplicationInfo.java
Normal file
File diff suppressed because it is too large
Load Diff
170
src/api-impl/android/content/pm/ComponentInfo.java
Normal file
170
src/api-impl/android/content/pm/ComponentInfo.java
Normal file
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
//import android.graphics.drawable.Drawable;
|
||||
import android.util.Printer;
|
||||
|
||||
/**
|
||||
* Base class containing information common to all application components
|
||||
* ({@link ActivityInfo}, {@link ServiceInfo}). This class is not intended
|
||||
* to be used by itself; it is simply here to share common definitions
|
||||
* between all application components. As such, it does not itself
|
||||
* implement Parcelable, but does provide convenience methods to assist
|
||||
* in the implementation of Parcelable in subclasses.
|
||||
*/
|
||||
public class ComponentInfo extends PackageItemInfo {
|
||||
/**
|
||||
* Global information about the application/package this component is a
|
||||
* part of.
|
||||
*/
|
||||
public ApplicationInfo applicationInfo;
|
||||
|
||||
/**
|
||||
* The name of the process this component should run in.
|
||||
* From the "android:process" attribute or, if not set, the same
|
||||
* as <var>applicationInfo.processName</var>.
|
||||
*/
|
||||
public String processName;
|
||||
|
||||
/**
|
||||
* A string resource identifier (in the package's resources) containing
|
||||
* a user-readable description of the component. From the "description"
|
||||
* attribute or, if not set, 0.
|
||||
*/
|
||||
public int descriptionRes;
|
||||
|
||||
/**
|
||||
* Indicates whether or not this component may be instantiated. Note that this value can be
|
||||
* overriden by the one in its parent {@link ApplicationInfo}.
|
||||
*/
|
||||
public boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Set to true if this component is available for use by other applications.
|
||||
* Comes from {@link android.R.attr#exported android:exported} of the
|
||||
* <activity>, <receiver>, <service>, or
|
||||
* <provider> tag.
|
||||
*/
|
||||
public boolean exported = false;
|
||||
|
||||
public ComponentInfo() {
|
||||
}
|
||||
|
||||
public ComponentInfo(ComponentInfo orig) {
|
||||
super(orig);
|
||||
applicationInfo = orig.applicationInfo;
|
||||
processName = orig.processName;
|
||||
descriptionRes = orig.descriptionRes;
|
||||
enabled = orig.enabled;
|
||||
exported = orig.exported;
|
||||
}
|
||||
|
||||
@Override public CharSequence loadLabel(PackageManager pm) {/*
|
||||
if (nonLocalizedLabel != null) {
|
||||
return nonLocalizedLabel;
|
||||
}
|
||||
ApplicationInfo ai = applicationInfo;
|
||||
CharSequence label;
|
||||
if (labelRes != 0) {
|
||||
label = pm.getText(packageName, labelRes, ai);
|
||||
if (label != null) {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
if (ai.nonLocalizedLabel != null) {
|
||||
return ai.nonLocalizedLabel;
|
||||
}
|
||||
if (ai.labelRes != 0) {
|
||||
label = pm.getText(packageName, ai.labelRes, ai);
|
||||
if (label != null) {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
*/return null;}
|
||||
|
||||
/**
|
||||
* Return whether this component and its enclosing application are enabled.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled /*&& applicationInfo.enabled*/;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the icon resource identifier to use for this component. If
|
||||
* the component defines an icon, that is used; else, the application
|
||||
* icon is used.
|
||||
*
|
||||
* @return The icon associated with this component.
|
||||
*/
|
||||
public final int getIconResource() {
|
||||
return icon;// != 0 ? icon : applicationInfo.icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the logo resource identifier to use for this component. If
|
||||
* the component defines a logo, that is used; else, the application
|
||||
* logo is used.
|
||||
*
|
||||
* @return The logo associated with this component.
|
||||
*/
|
||||
public final int getLogoResource() {
|
||||
return logo;// != 0 ? logo : applicationInfo.logo;
|
||||
}
|
||||
|
||||
protected void dumpFront(Printer pw, String prefix) {
|
||||
super.dumpFront(pw, prefix);
|
||||
pw.println(prefix + "enabled=" + enabled + " exported=" + exported
|
||||
+ " processName=" + processName);
|
||||
if (descriptionRes != 0) {
|
||||
pw.println(prefix + "description=" + descriptionRes);
|
||||
}
|
||||
}
|
||||
|
||||
protected void dumpBack(Printer pw, String prefix) {
|
||||
if (applicationInfo != null) {
|
||||
pw.println(prefix + "ApplicationInfo:");
|
||||
//applicationInfo.dump(pw, prefix + " ");
|
||||
} else {
|
||||
pw.println(prefix + "ApplicationInfo: null");
|
||||
}
|
||||
super.dumpBack(pw, prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@Override protected Drawable loadDefaultIcon(PackageManager pm) {
|
||||
return null;//applicationInfo.loadIcon(pm);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@Override
|
||||
protected Drawable loadDefaultLogo(PackageManager pm) {
|
||||
return null;//applicationInfo.loadLogo(pm);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@Override protected ApplicationInfo getApplicationInfo() {
|
||||
return applicationInfo;
|
||||
}
|
||||
}
|
||||
116
src/api-impl/android/content/pm/ConfigurationInfo.java
Normal file
116
src/api-impl/android/content/pm/ConfigurationInfo.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
/**
|
||||
* Information you can retrieve about hardware configuration preferences
|
||||
* declared by an application. This corresponds to information collected from the
|
||||
* AndroidManifest.xml's <uses-configuration> and <uses-feature> tags.
|
||||
*/
|
||||
public class ConfigurationInfo {
|
||||
/**
|
||||
* The kind of touch screen attached to the device.
|
||||
* One of: {@link android.content.res.Configuration#TOUCHSCREEN_NOTOUCH},
|
||||
* {@link android.content.res.Configuration#TOUCHSCREEN_STYLUS},
|
||||
* {@link android.content.res.Configuration#TOUCHSCREEN_FINGER}.
|
||||
*/
|
||||
public int reqTouchScreen;
|
||||
|
||||
/**
|
||||
* Application's input method preference.
|
||||
* One of: {@link android.content.res.Configuration#KEYBOARD_UNDEFINED},
|
||||
* {@link android.content.res.Configuration#KEYBOARD_NOKEYS},
|
||||
* {@link android.content.res.Configuration#KEYBOARD_QWERTY},
|
||||
* {@link android.content.res.Configuration#KEYBOARD_12KEY}
|
||||
*/
|
||||
public int reqKeyboardType;
|
||||
|
||||
/**
|
||||
* A flag indicating whether any keyboard is available.
|
||||
* one of: {@link android.content.res.Configuration#NAVIGATION_UNDEFINED},
|
||||
* {@link android.content.res.Configuration#NAVIGATION_DPAD},
|
||||
* {@link android.content.res.Configuration#NAVIGATION_TRACKBALL},
|
||||
* {@link android.content.res.Configuration#NAVIGATION_WHEEL}
|
||||
*/
|
||||
public int reqNavigation;
|
||||
|
||||
/**
|
||||
* Value for {@link #reqInputFeatures}: if set, indicates that the application
|
||||
* requires a hard keyboard
|
||||
*/
|
||||
public static final int INPUT_FEATURE_HARD_KEYBOARD = 0x00000001;
|
||||
|
||||
/**
|
||||
* Value for {@link #reqInputFeatures}: if set, indicates that the application
|
||||
* requires a five way navigation device
|
||||
*/
|
||||
public static final int INPUT_FEATURE_FIVE_WAY_NAV = 0x00000002;
|
||||
|
||||
/**
|
||||
* Flags associated with the input features. Any combination of
|
||||
* {@link #INPUT_FEATURE_HARD_KEYBOARD},
|
||||
* {@link #INPUT_FEATURE_FIVE_WAY_NAV}
|
||||
*/
|
||||
public int reqInputFeatures = 0;
|
||||
|
||||
/**
|
||||
* Default value for {@link #reqGlEsVersion};
|
||||
*/
|
||||
public static final int GL_ES_VERSION_UNDEFINED = 0;
|
||||
/**
|
||||
* The GLES version used by an application. The upper order 16 bits represent the
|
||||
* major version and the lower order 16 bits the minor version.
|
||||
*/
|
||||
public int reqGlEsVersion;
|
||||
|
||||
public ConfigurationInfo() {
|
||||
}
|
||||
|
||||
public ConfigurationInfo(ConfigurationInfo orig) {
|
||||
reqTouchScreen = orig.reqTouchScreen;
|
||||
reqKeyboardType = orig.reqKeyboardType;
|
||||
reqNavigation = orig.reqNavigation;
|
||||
reqInputFeatures = orig.reqInputFeatures;
|
||||
reqGlEsVersion = orig.reqGlEsVersion;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ConfigurationInfo{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " touchscreen = " + reqTouchScreen
|
||||
+ " inputMethod = " + reqKeyboardType
|
||||
+ " navigation = " + reqNavigation
|
||||
+ " reqInputFeatures = " + reqInputFeatures
|
||||
+ " reqGlEsVersion = " + reqGlEsVersion + "}";
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method extracts the major and minor version of reqGLEsVersion attribute
|
||||
* and returns it as a string. Say reqGlEsVersion value of 0x00010002 is returned
|
||||
* as 1.2
|
||||
* @return String representation of the reqGlEsVersion attribute
|
||||
*/
|
||||
public String getGlEsVersion() {
|
||||
int major = ((reqGlEsVersion & 0xffff0000) >> 16);
|
||||
int minor = reqGlEsVersion & 0x0000ffff;
|
||||
return String.valueOf(major)+"."+String.valueOf(minor);
|
||||
}
|
||||
}
|
||||
91
src/api-impl/android/content/pm/FeatureInfo.java
Normal file
91
src/api-impl/android/content/pm/FeatureInfo.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
/**
|
||||
* A single feature that can be requested by an application. This corresponds
|
||||
* to information collected from the
|
||||
* AndroidManifest.xml's <uses-feature> tag.
|
||||
*/
|
||||
public class FeatureInfo {
|
||||
/**
|
||||
* The name of this feature, for example "android.hardware.camera". If
|
||||
* this is null, then this is an OpenGL ES version feature as described
|
||||
* in {@link #reqGlEsVersion}.
|
||||
*/
|
||||
public String name;
|
||||
|
||||
/**
|
||||
* Default value for {@link #reqGlEsVersion};
|
||||
*/
|
||||
public static final int GL_ES_VERSION_UNDEFINED = 0;
|
||||
|
||||
/**
|
||||
* The GLES version used by an application. The upper order 16 bits represent the
|
||||
* major version and the lower order 16 bits the minor version. Only valid
|
||||
* if {@link #name} is null.
|
||||
*/
|
||||
public int reqGlEsVersion;
|
||||
|
||||
/**
|
||||
* Set on {@link #flags} if this feature has been required by the application.
|
||||
*/
|
||||
public static final int FLAG_REQUIRED = 0x0001;
|
||||
|
||||
/**
|
||||
* Additional flags. May be zero or more of {@link #FLAG_REQUIRED}.
|
||||
*/
|
||||
public int flags;
|
||||
|
||||
public FeatureInfo() {
|
||||
}
|
||||
|
||||
public FeatureInfo(FeatureInfo orig) {
|
||||
name = orig.name;
|
||||
reqGlEsVersion = orig.reqGlEsVersion;
|
||||
flags = orig.flags;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (name != null) {
|
||||
return "FeatureInfo{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " " + name + " fl=0x" + Integer.toHexString(flags) + "}";
|
||||
} else {
|
||||
return "FeatureInfo{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " glEsVers=" + getGlEsVersion()
|
||||
+ " fl=0x" + Integer.toHexString(flags) + "}";
|
||||
}
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method extracts the major and minor version of reqGLEsVersion attribute
|
||||
* and returns it as a string. Say reqGlEsVersion value of 0x00010002 is returned
|
||||
* as 1.2
|
||||
* @return String representation of the reqGlEsVersion attribute
|
||||
*/
|
||||
public String getGlEsVersion() {
|
||||
int major = ((reqGlEsVersion & 0xffff0000) >> 16);
|
||||
int minor = reqGlEsVersion & 0x0000ffff;
|
||||
return String.valueOf(major)+"."+String.valueOf(minor);
|
||||
}
|
||||
}
|
||||
85
src/api-impl/android/content/pm/InstrumentationInfo.java
Normal file
85
src/api-impl/android/content/pm/InstrumentationInfo.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
/**
|
||||
* Information you can retrieve about a particular piece of test
|
||||
* instrumentation. This corresponds to information collected
|
||||
* from the AndroidManifest.xml's <instrumentation> tag.
|
||||
*/
|
||||
public class InstrumentationInfo extends PackageItemInfo {
|
||||
/**
|
||||
* The name of the application package being instrumented. From the
|
||||
* "package" attribute.
|
||||
*/
|
||||
public String targetPackage;
|
||||
|
||||
/**
|
||||
* Full path to the location of this package.
|
||||
*/
|
||||
public String sourceDir;
|
||||
|
||||
/**
|
||||
* Full path to the location of the publicly available parts of this package (i.e. the resources
|
||||
* and manifest). For non-forward-locked apps this will be the same as {@link #sourceDir).
|
||||
*/
|
||||
public String publicSourceDir;
|
||||
/**
|
||||
* Full path to a directory assigned to the package for its persistent
|
||||
* data.
|
||||
*/
|
||||
public String dataDir;
|
||||
|
||||
/**
|
||||
* Full path to the directory where the native JNI libraries are stored.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public String nativeLibraryDir;
|
||||
|
||||
/**
|
||||
* Specifies whether or not this instrumentation will handle profiling.
|
||||
*/
|
||||
public boolean handleProfiling;
|
||||
|
||||
/** Specifies whether or not to run this instrumentation as a functional test */
|
||||
public boolean functionalTest;
|
||||
|
||||
public InstrumentationInfo() {
|
||||
}
|
||||
|
||||
public InstrumentationInfo(InstrumentationInfo orig) {
|
||||
super(orig);
|
||||
targetPackage = orig.targetPackage;
|
||||
sourceDir = orig.sourceDir;
|
||||
publicSourceDir = orig.publicSourceDir;
|
||||
dataDir = orig.dataDir;
|
||||
nativeLibraryDir = orig.nativeLibraryDir;
|
||||
handleProfiling = orig.handleProfiling;
|
||||
functionalTest = orig.functionalTest;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "InstrumentationInfo{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " " + packageName + "}";
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
119
src/api-impl/android/content/pm/ManifestDigest.java
Normal file
119
src/api-impl/android/content/pm/ManifestDigest.java
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
import android.util.Slog;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
/**
|
||||
* Represents the manifest digest for a package. This is suitable for comparison
|
||||
* of two packages to know whether the manifests are identical.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class ManifestDigest {
|
||||
private static final String TAG = "ManifestDigest";
|
||||
|
||||
/** The digest of the manifest in our preferred order. */
|
||||
private final byte[] mDigest;
|
||||
|
||||
/** What we print out first when toString() is called. */
|
||||
private static final String TO_STRING_PREFIX = "ManifestDigest {mDigest=";
|
||||
|
||||
/** Digest algorithm to use. */
|
||||
private static final String DIGEST_ALGORITHM = "SHA-256";
|
||||
|
||||
ManifestDigest(byte[] digest) {
|
||||
mDigest = digest;
|
||||
}
|
||||
|
||||
static ManifestDigest fromInputStream(InputStream fileIs) {
|
||||
if (fileIs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final MessageDigest md;
|
||||
try {
|
||||
md = MessageDigest.getInstance(DIGEST_ALGORITHM);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(DIGEST_ALGORITHM + " must be available", e);
|
||||
}
|
||||
|
||||
final DigestInputStream dis = new DigestInputStream(new BufferedInputStream(fileIs), md);
|
||||
try {
|
||||
byte[] readBuffer = new byte[8192];
|
||||
while (dis.read(readBuffer, 0, readBuffer.length) != -1) {
|
||||
// not using
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Slog.w(TAG, "Could not read manifest");
|
||||
return null;
|
||||
} finally {
|
||||
IoUtils.closeQuietly(dis);
|
||||
}
|
||||
|
||||
final byte[] digest = md.digest();
|
||||
return new ManifestDigest(digest);
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof ManifestDigest)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ManifestDigest other = (ManifestDigest) o;
|
||||
|
||||
return this == other || Arrays.equals(mDigest, other.mDigest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(mDigest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX.length()
|
||||
+ (mDigest.length * 3) + 1);
|
||||
|
||||
sb.append(TO_STRING_PREFIX);
|
||||
|
||||
final int N = mDigest.length;
|
||||
for (int i = 0; i < N; i++) {
|
||||
final byte b = mDigest[i];
|
||||
IntegralToString.appendByteAsHex(sb, b, false);
|
||||
sb.append(',');
|
||||
}
|
||||
sb.append('}');
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
240
src/api-impl/android/content/pm/PackageInfo.java
Normal file
240
src/api-impl/android/content/pm/PackageInfo.java
Normal file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
/**
|
||||
* Overall information about the contents of a package. This corresponds
|
||||
* to all of the information collected from AndroidManifest.xml.
|
||||
*/
|
||||
public class PackageInfo {
|
||||
/**
|
||||
* The name of this package. From the <manifest> tag's "name"
|
||||
* attribute.
|
||||
*/
|
||||
public String packageName = "com.example.app"; // FIXME
|
||||
|
||||
/**
|
||||
* The version number of this package, as specified by the <manifest>
|
||||
* tag's {@link android.R.styleable#AndroidManifest_versionCode versionCode}
|
||||
* attribute.
|
||||
*/
|
||||
public int versionCode = 1; //FIXME
|
||||
|
||||
/**
|
||||
* The version name of this package, as specified by the <manifest>
|
||||
* tag's {@link android.R.styleable#AndroidManifest_versionName versionName}
|
||||
* attribute.
|
||||
*/
|
||||
public String versionName = "v0.FIXME";
|
||||
|
||||
/**
|
||||
* The shared user ID name of this package, as specified by the <manifest>
|
||||
* tag's {@link android.R.styleable#AndroidManifest_sharedUserId sharedUserId}
|
||||
* attribute.
|
||||
*/
|
||||
public String sharedUserId;
|
||||
|
||||
/**
|
||||
* The shared user ID label of this package, as specified by the <manifest>
|
||||
* tag's {@link android.R.styleable#AndroidManifest_sharedUserLabel sharedUserLabel}
|
||||
* attribute.
|
||||
*/
|
||||
public int sharedUserLabel;
|
||||
|
||||
/**
|
||||
* Information collected from the <application> tag, or null if
|
||||
* there was none.
|
||||
*/
|
||||
public ApplicationInfo applicationInfo;
|
||||
|
||||
/**
|
||||
* The time at which the app was first installed. Units are as
|
||||
* per {@link System#currentTimeMillis()}.
|
||||
*/
|
||||
public long firstInstallTime;
|
||||
|
||||
/**
|
||||
* The time at which the app was last updated. Units are as
|
||||
* per {@link System#currentTimeMillis()}.
|
||||
*/
|
||||
public long lastUpdateTime;
|
||||
|
||||
/**
|
||||
* All kernel group-IDs that have been assigned to this package.
|
||||
* This is only filled in if the flag {@link PackageManager#GET_GIDS} was set.
|
||||
*/
|
||||
public int[] gids;
|
||||
|
||||
/**
|
||||
* Array of all {@link android.R.styleable#AndroidManifestActivity
|
||||
* <activity>} tags included under <application>,
|
||||
* or null if there were none. This is only filled in if the flag
|
||||
* {@link PackageManager#GET_ACTIVITIES} was set.
|
||||
*/
|
||||
public ActivityInfo[] activities;
|
||||
|
||||
/**
|
||||
* Array of all {@link android.R.styleable#AndroidManifestReceiver
|
||||
* <receiver>} tags included under <application>,
|
||||
* or null if there were none. This is only filled in if the flag
|
||||
* {@link PackageManager#GET_RECEIVERS} was set.
|
||||
*/
|
||||
public ActivityInfo[] receivers;
|
||||
|
||||
/**
|
||||
* Array of all {@link android.R.styleable#AndroidManifestService
|
||||
* <service>} tags included under <application>,
|
||||
* or null if there were none. This is only filled in if the flag
|
||||
* {@link PackageManager#GET_SERVICES} was set.
|
||||
*/
|
||||
public ServiceInfo[] services;
|
||||
|
||||
/**
|
||||
* Array of all {@link android.R.styleable#AndroidManifestProvider
|
||||
* <provider>} tags included under <application>,
|
||||
* or null if there were none. This is only filled in if the flag
|
||||
* {@link PackageManager#GET_PROVIDERS} was set.
|
||||
*/
|
||||
public ProviderInfo[] providers;
|
||||
|
||||
/**
|
||||
* Array of all {@link android.R.styleable#AndroidManifestInstrumentation
|
||||
* <instrumentation>} tags included under <manifest>,
|
||||
* or null if there were none. This is only filled in if the flag
|
||||
* {@link PackageManager#GET_INSTRUMENTATION} was set.
|
||||
*/
|
||||
public InstrumentationInfo[] instrumentation;
|
||||
|
||||
/**
|
||||
* Array of all {@link android.R.styleable#AndroidManifestPermission
|
||||
* <permission>} tags included under <manifest>,
|
||||
* or null if there were none. This is only filled in if the flag
|
||||
* {@link PackageManager#GET_PERMISSIONS} was set.
|
||||
*/
|
||||
public PermissionInfo[] permissions;
|
||||
|
||||
/**
|
||||
* Array of all {@link android.R.styleable#AndroidManifestUsesPermission
|
||||
* <uses-permission>} tags included under <manifest>,
|
||||
* or null if there were none. This is only filled in if the flag
|
||||
* {@link PackageManager#GET_PERMISSIONS} was set. This list includes
|
||||
* all permissions requested, even those that were not granted or known
|
||||
* by the system at install time.
|
||||
*/
|
||||
public String[] requestedPermissions;
|
||||
|
||||
/**
|
||||
* Array of flags of all {@link android.R.styleable#AndroidManifestUsesPermission
|
||||
* <uses-permission>} tags included under <manifest>,
|
||||
* or null if there were none. This is only filled in if the flag
|
||||
* {@link PackageManager#GET_PERMISSIONS} was set. Each value matches
|
||||
* the corresponding entry in {@link #requestedPermissions}, and will have
|
||||
* the flags {@link #REQUESTED_PERMISSION_REQUIRED} and
|
||||
* {@link #REQUESTED_PERMISSION_GRANTED} set as appropriate.
|
||||
*/
|
||||
public int[] requestedPermissionsFlags;
|
||||
|
||||
/**
|
||||
* Flag for {@link #requestedPermissionsFlags}: the requested permission
|
||||
* is required for the application to run; the user can not optionally
|
||||
* disable it. Currently all permissions are required.
|
||||
*/
|
||||
public static final int REQUESTED_PERMISSION_REQUIRED = 1<<0;
|
||||
|
||||
/**
|
||||
* Flag for {@link #requestedPermissionsFlags}: the requested permission
|
||||
* is currently granted to the application.
|
||||
*/
|
||||
public static final int REQUESTED_PERMISSION_GRANTED = 1<<1;
|
||||
|
||||
/**
|
||||
* Array of all signatures read from the package file. This is only filled
|
||||
* in if the flag {@link PackageManager#GET_SIGNATURES} was set.
|
||||
*/
|
||||
public Signature[] signatures;
|
||||
|
||||
/**
|
||||
* Application specified preferred configuration
|
||||
* {@link android.R.styleable#AndroidManifestUsesConfiguration
|
||||
* <uses-configuration>} tags included under <manifest>,
|
||||
* or null if there were none. This is only filled in if the flag
|
||||
* {@link PackageManager#GET_CONFIGURATIONS} was set.
|
||||
*/
|
||||
public ConfigurationInfo[] configPreferences;
|
||||
|
||||
/**
|
||||
* The features that this application has said it requires.
|
||||
*/
|
||||
public FeatureInfo[] reqFeatures;
|
||||
|
||||
/**
|
||||
* Constant corresponding to <code>auto</code> in
|
||||
* the {@link android.R.attr#installLocation} attribute.
|
||||
* @hide
|
||||
*/
|
||||
public static final int INSTALL_LOCATION_UNSPECIFIED = -1;
|
||||
/**
|
||||
* Constant corresponding to <code>auto</code> in
|
||||
* the {@link android.R.attr#installLocation} attribute.
|
||||
* @hide
|
||||
*/
|
||||
public static final int INSTALL_LOCATION_AUTO = 0;
|
||||
/**
|
||||
* Constant corresponding to <code>internalOnly</code> in
|
||||
* the {@link android.R.attr#installLocation} attribute.
|
||||
* @hide
|
||||
*/
|
||||
public static final int INSTALL_LOCATION_INTERNAL_ONLY = 1;
|
||||
/**
|
||||
* Constant corresponding to <code>preferExternal</code> in
|
||||
* the {@link android.R.attr#installLocation} attribute.
|
||||
* @hide
|
||||
*/
|
||||
public static final int INSTALL_LOCATION_PREFER_EXTERNAL = 2;
|
||||
/**
|
||||
* The install location requested by the activity. From the
|
||||
* {@link android.R.attr#installLocation} attribute, one of
|
||||
* {@link #INSTALL_LOCATION_AUTO},
|
||||
* {@link #INSTALL_LOCATION_INTERNAL_ONLY},
|
||||
* {@link #INSTALL_LOCATION_PREFER_EXTERNAL}
|
||||
* @hide
|
||||
*/
|
||||
public int installLocation = INSTALL_LOCATION_INTERNAL_ONLY;
|
||||
|
||||
/** @hide */
|
||||
public boolean requiredForAllUsers;
|
||||
|
||||
/** @hide */
|
||||
public String restrictedAccountType;
|
||||
|
||||
/** @hide */
|
||||
public String requiredAccountType;
|
||||
|
||||
public PackageInfo() {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "PackageInfo{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " " + packageName + "}";
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
266
src/api-impl/android/content/pm/PackageItemInfo.java
Normal file
266
src/api-impl/android/content/pm/PackageItemInfo.java
Normal file
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
import android.content.res.XmlResourceParser;
|
||||
|
||||
//import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
//import android.text.TextUtils;
|
||||
import android.util.Printer;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Base class containing information common to all package items held by
|
||||
* the package manager. This provides a very common basic set of attributes:
|
||||
* a label, icon, and meta-data. This class is not intended
|
||||
* to be used by itself; it is simply here to share common definitions
|
||||
* between all items returned by the package manager. As such, it does not
|
||||
* itself implement Parcelable, but does provide convenience methods to assist
|
||||
* in the implementation of Parcelable in subclasses.
|
||||
*/
|
||||
public class PackageItemInfo {
|
||||
/**
|
||||
* Public name of this item. From the "android:name" attribute.
|
||||
*/
|
||||
public String name;
|
||||
|
||||
/**
|
||||
* Name of the package that this item is in.
|
||||
*/
|
||||
public String packageName;
|
||||
|
||||
/**
|
||||
* A string resource identifier (in the package's resources) of this
|
||||
* component's label. From the "label" attribute or, if not set, 0.
|
||||
*/
|
||||
public int labelRes;
|
||||
|
||||
/**
|
||||
* The string provided in the AndroidManifest file, if any. You
|
||||
* probably don't want to use this. You probably want
|
||||
* {@link PackageManager#getApplicationLabel}
|
||||
*/
|
||||
public CharSequence nonLocalizedLabel;
|
||||
|
||||
/**
|
||||
* A drawable resource identifier (in the package's resources) of this
|
||||
* component's icon. From the "icon" attribute or, if not set, 0.
|
||||
*/
|
||||
public int icon;
|
||||
|
||||
/**
|
||||
* A drawable resource identifier (in the package's resources) of this
|
||||
* component's logo. Logos may be larger/wider than icons and are
|
||||
* displayed by certain UI elements in place of a name or name/icon
|
||||
* combination. From the "logo" attribute or, if not set, 0.
|
||||
*/
|
||||
public int logo;
|
||||
|
||||
/**
|
||||
* Additional meta-data associated with this component. This field
|
||||
* will only be filled in if you set the
|
||||
* {@link PackageManager#GET_META_DATA} flag when requesting the info.
|
||||
*/
|
||||
public Bundle metaData;
|
||||
|
||||
public PackageItemInfo() {
|
||||
}
|
||||
|
||||
public PackageItemInfo(PackageItemInfo orig) {
|
||||
name = orig.name;
|
||||
if (name != null) name = name.trim();
|
||||
packageName = orig.packageName;
|
||||
labelRes = orig.labelRes;
|
||||
nonLocalizedLabel = orig.nonLocalizedLabel;
|
||||
if (nonLocalizedLabel != null) nonLocalizedLabel = nonLocalizedLabel.toString().trim();
|
||||
icon = orig.icon;
|
||||
logo = orig.logo;
|
||||
metaData = orig.metaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current textual label associated with this item. This
|
||||
* will call back on the given PackageManager to load the label from
|
||||
* the application.
|
||||
*
|
||||
* @param pm A PackageManager from which the label can be loaded; usually
|
||||
* the PackageManager from which you originally retrieved this item.
|
||||
*
|
||||
* @return Returns a CharSequence containing the item's label. If the
|
||||
* item does not have a label, its name is returned.
|
||||
*/
|
||||
public CharSequence loadLabel(PackageManager pm) {
|
||||
if (nonLocalizedLabel != null) {
|
||||
return nonLocalizedLabel;
|
||||
}
|
||||
if (labelRes != 0) {
|
||||
CharSequence label = pm.getText(packageName, labelRes, getApplicationInfo());
|
||||
if (label != null) {
|
||||
return label.toString().trim();
|
||||
}
|
||||
}
|
||||
if (name != null) {
|
||||
return name;
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current graphical icon associated with this item. This
|
||||
* will call back on the given PackageManager to load the icon from
|
||||
* the application.
|
||||
*
|
||||
* @param pm A PackageManager from which the icon can be loaded; usually
|
||||
* the PackageManager from which you originally retrieved this item.
|
||||
*
|
||||
* @return Returns a Drawable containing the item's icon. If the
|
||||
* item does not have an icon, the item's default icon is returned
|
||||
* such as the default activity icon.
|
||||
*/
|
||||
public Drawable loadIcon(PackageManager pm) {
|
||||
if (icon != 0) {
|
||||
Drawable dr = pm.getDrawable(packageName, icon, getApplicationInfo());
|
||||
if (dr != null) {
|
||||
return dr;
|
||||
}
|
||||
}
|
||||
return loadDefaultIcon(pm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default graphical icon associated with this item.
|
||||
*
|
||||
* @param pm A PackageManager from which the icon can be loaded; usually
|
||||
* the PackageManager from which you originally retrieved this item.
|
||||
*
|
||||
* @return Returns a Drawable containing the item's default icon
|
||||
* such as the default activity icon.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
protected Drawable loadDefaultIcon(PackageManager pm) {
|
||||
return pm.getDefaultActivityIcon();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current graphical logo associated with this item. This
|
||||
* will call back on the given PackageManager to load the logo from
|
||||
* the application.
|
||||
*
|
||||
* @param pm A PackageManager from which the logo can be loaded; usually
|
||||
* the PackageManager from which you originally retrieved this item.
|
||||
*
|
||||
* @return Returns a Drawable containing the item's logo. If the item
|
||||
* does not have a logo, this method will return null.
|
||||
*/
|
||||
public Drawable loadLogo(PackageManager pm) {
|
||||
if (logo != 0) {
|
||||
Drawable d = pm.getDrawable(packageName, logo, getApplicationInfo());
|
||||
if (d != null) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return loadDefaultLogo(pm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the default graphical logo associated with this item.
|
||||
*
|
||||
* @param pm A PackageManager from which the logo can be loaded; usually
|
||||
* the PackageManager from which you originally retrieved this item.
|
||||
*
|
||||
* @return Returns a Drawable containing the item's default logo
|
||||
* or null if no default logo is available.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
protected Drawable loadDefaultLogo(PackageManager pm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an XML resource attached to the meta-data of this item. This will
|
||||
* retrieved the name meta-data entry, and if defined call back on the
|
||||
* given PackageManager to load its XML file from the application.
|
||||
*
|
||||
* @param pm A PackageManager from which the XML can be loaded; usually
|
||||
* the PackageManager from which you originally retrieved this item.
|
||||
* @param name Name of the meta-date you would like to load.
|
||||
*
|
||||
* @return Returns an XmlPullParser you can use to parse the XML file
|
||||
* assigned as the given meta-data. If the meta-data name is not defined
|
||||
* or the XML resource could not be found, null is returned.
|
||||
*/
|
||||
public XmlResourceParser loadXmlMetaData(PackageManager pm, String name) {
|
||||
if (metaData != null) {
|
||||
int resid = metaData.getInt(name);
|
||||
if (resid != 0) {
|
||||
return pm.getXml(packageName, resid, getApplicationInfo());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void dumpFront(Printer pw, String prefix) {
|
||||
if (name != null) {
|
||||
pw.println(prefix + "name=" + name);
|
||||
}
|
||||
pw.println(prefix + "packageName=" + packageName);
|
||||
if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) {
|
||||
pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes)
|
||||
+ " nonLocalizedLabel=" + nonLocalizedLabel
|
||||
+ " icon=0x" + Integer.toHexString(icon));
|
||||
}
|
||||
}
|
||||
|
||||
protected void dumpBack(Printer pw, String prefix) {
|
||||
// no back here
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ApplicationInfo for the application to which this item belongs,
|
||||
* if available, otherwise returns null.
|
||||
*
|
||||
* @return Returns the ApplicationInfo of this item, or null if not known.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
protected ApplicationInfo getApplicationInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class DisplayNameComparator
|
||||
implements Comparator<PackageItemInfo> {
|
||||
public DisplayNameComparator(PackageManager pm) {
|
||||
mPM = pm;
|
||||
}
|
||||
|
||||
public final int compare(PackageItemInfo aa, PackageItemInfo ab) {
|
||||
CharSequence sa = aa.loadLabel(mPM);
|
||||
if (sa == null) sa = aa.name;
|
||||
CharSequence sb = ab.loadLabel(mPM);
|
||||
if (sb == null) sb = ab.name;
|
||||
return sCollator.compare(sa.toString(), sb.toString());
|
||||
}
|
||||
|
||||
private final Collator sCollator = Collator.getInstance();
|
||||
private PackageManager mPM;
|
||||
}
|
||||
}
|
||||
3407
src/api-impl/android/content/pm/PackageManager.java
Normal file
3407
src/api-impl/android/content/pm/PackageManager.java
Normal file
File diff suppressed because it is too large
Load Diff
3939
src/api-impl/android/content/pm/PackageParser.java
Normal file
3939
src/api-impl/android/content/pm/PackageParser.java
Normal file
File diff suppressed because it is too large
Load Diff
57
src/api-impl/android/content/pm/PackageUserState.java
Normal file
57
src/api-impl/android/content/pm/PackageUserState.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Per-user state information about a package.
|
||||
* @hide
|
||||
*/
|
||||
public class PackageUserState {
|
||||
public boolean stopped;
|
||||
public boolean notLaunched;
|
||||
public boolean installed;
|
||||
public boolean blocked; // Is the app restricted by owner / admin
|
||||
public int enabled;
|
||||
|
||||
public String lastDisableAppCaller;
|
||||
|
||||
public HashSet<String> disabledComponents;
|
||||
public HashSet<String> enabledComponents;
|
||||
|
||||
public PackageUserState() {
|
||||
installed = true;
|
||||
blocked = false;
|
||||
enabled = COMPONENT_ENABLED_STATE_DEFAULT;
|
||||
}
|
||||
|
||||
public PackageUserState(PackageUserState o) {
|
||||
installed = o.installed;
|
||||
stopped = o.stopped;
|
||||
notLaunched = o.notLaunched;
|
||||
enabled = o.enabled;
|
||||
blocked = o.blocked;
|
||||
lastDisableAppCaller = o.lastDisableAppCaller;
|
||||
disabledComponents = o.disabledComponents != null
|
||||
? new HashSet<String>(o.disabledComponents) : null;
|
||||
enabledComponents = o.enabledComponents != null
|
||||
? new HashSet<String>(o.enabledComponents) : null;
|
||||
}
|
||||
}
|
||||
43
src/api-impl/android/content/pm/PathPermission.java
Normal file
43
src/api-impl/android/content/pm/PathPermission.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
import android.os.PatternMatcher;
|
||||
|
||||
/**
|
||||
* Description of permissions needed to access a particular path
|
||||
* in a {@link ProviderInfo}.
|
||||
*/
|
||||
public class PathPermission extends PatternMatcher {
|
||||
private final String mReadPermission;
|
||||
private final String mWritePermission;
|
||||
|
||||
public PathPermission(String pattern, int type, String readPermission,
|
||||
String writePermission) {
|
||||
super(pattern, type);
|
||||
mReadPermission = readPermission;
|
||||
mWritePermission = writePermission;
|
||||
}
|
||||
|
||||
public String getReadPermission() {
|
||||
return mReadPermission;
|
||||
}
|
||||
|
||||
public String getWritePermission() {
|
||||
return mWritePermission;
|
||||
}
|
||||
}
|
||||
103
src/api-impl/android/content/pm/PermissionGroupInfo.java
Normal file
103
src/api-impl/android/content/pm/PermissionGroupInfo.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
//import android.text.TextUtils;
|
||||
|
||||
/**
|
||||
* Information you can retrieve about a particular security permission
|
||||
* group known to the system. This corresponds to information collected from the
|
||||
* AndroidManifest.xml's <permission-group> tags.
|
||||
*/
|
||||
public class PermissionGroupInfo extends PackageItemInfo {
|
||||
/**
|
||||
* A string resource identifier (in the package's resources) of this
|
||||
* permission's description. From the "description" attribute or,
|
||||
* if not set, 0.
|
||||
*/
|
||||
public int descriptionRes;
|
||||
|
||||
/**
|
||||
* The description string provided in the AndroidManifest file, if any. You
|
||||
* probably don't want to use this, since it will be null if the description
|
||||
* is in a resource. You probably want
|
||||
* {@link PermissionInfo#loadDescription} instead.
|
||||
*/
|
||||
public CharSequence nonLocalizedDescription;
|
||||
|
||||
/**
|
||||
* Flag for {@link #flags}, corresponding to <code>personalInfo</code>
|
||||
* value of {@link android.R.attr#permissionGroupFlags}.
|
||||
*/
|
||||
public static final int FLAG_PERSONAL_INFO = 1<<0;
|
||||
|
||||
/**
|
||||
* Additional flags about this group as given by
|
||||
* {@link android.R.attr#permissionGroupFlags}.
|
||||
*/
|
||||
public int flags;
|
||||
|
||||
/**
|
||||
* Prioritization of this group, for visually sorting with other groups.
|
||||
*/
|
||||
public int priority;
|
||||
|
||||
public PermissionGroupInfo() {
|
||||
}
|
||||
|
||||
public PermissionGroupInfo(PermissionGroupInfo orig) {
|
||||
super(orig);
|
||||
descriptionRes = orig.descriptionRes;
|
||||
nonLocalizedDescription = orig.nonLocalizedDescription;
|
||||
flags = orig.flags;
|
||||
priority = orig.priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the textual description of this permission. This
|
||||
* will call back on the given PackageManager to load the description from
|
||||
* the application.
|
||||
*
|
||||
* @param pm A PackageManager from which the label can be loaded; usually
|
||||
* the PackageManager from which you originally retrieved this item.
|
||||
*
|
||||
* @return Returns a CharSequence containing the permission's description.
|
||||
* If there is no description, null is returned.
|
||||
*/
|
||||
public CharSequence loadDescription(PackageManager pm) {
|
||||
if (nonLocalizedDescription != null) {
|
||||
return nonLocalizedDescription;
|
||||
}
|
||||
if (descriptionRes != 0) {
|
||||
CharSequence label = pm.getText(packageName, descriptionRes, null);
|
||||
if (label != null) {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "PermissionGroupInfo{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " " + name + " flgs=0x" + Integer.toHexString(flags) + "}";
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
200
src/api-impl/android/content/pm/PermissionInfo.java
Normal file
200
src/api-impl/android/content/pm/PermissionInfo.java
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
/**
|
||||
* Information you can retrieve about a particular security permission
|
||||
* known to the system. This corresponds to information collected from the
|
||||
* AndroidManifest.xml's <permission> tags.
|
||||
*/
|
||||
public class PermissionInfo extends PackageItemInfo {
|
||||
/**
|
||||
* A normal application value for {@link #protectionLevel}, corresponding
|
||||
* to the <code>normal</code> value of
|
||||
* {@link android.R.attr#protectionLevel}.
|
||||
*/
|
||||
public static final int PROTECTION_NORMAL = 0;
|
||||
|
||||
/**
|
||||
* Dangerous value for {@link #protectionLevel}, corresponding
|
||||
* to the <code>dangerous</code> value of
|
||||
* {@link android.R.attr#protectionLevel}.
|
||||
*/
|
||||
public static final int PROTECTION_DANGEROUS = 1;
|
||||
|
||||
/**
|
||||
* System-level value for {@link #protectionLevel}, corresponding
|
||||
* to the <code>signature</code> value of
|
||||
* {@link android.R.attr#protectionLevel}.
|
||||
*/
|
||||
public static final int PROTECTION_SIGNATURE = 2;
|
||||
|
||||
/**
|
||||
* System-level value for {@link #protectionLevel}, corresponding
|
||||
* to the <code>signatureOrSystem</code> value of
|
||||
* {@link android.R.attr#protectionLevel}.
|
||||
*/
|
||||
public static final int PROTECTION_SIGNATURE_OR_SYSTEM = 3;
|
||||
|
||||
/**
|
||||
* Additional flag for {@link #protectionLevel}, corresponding
|
||||
* to the <code>system</code> value of
|
||||
* {@link android.R.attr#protectionLevel}.
|
||||
*/
|
||||
public static final int PROTECTION_FLAG_SYSTEM = 0x10;
|
||||
|
||||
/**
|
||||
* Additional flag for {@link #protectionLevel}, corresponding
|
||||
* to the <code>development</code> value of
|
||||
* {@link android.R.attr#protectionLevel}.
|
||||
*/
|
||||
public static final int PROTECTION_FLAG_DEVELOPMENT = 0x20;
|
||||
|
||||
/**
|
||||
* Mask for {@link #protectionLevel}: the basic protection type.
|
||||
*/
|
||||
public static final int PROTECTION_MASK_BASE = 0xf;
|
||||
|
||||
/**
|
||||
* Mask for {@link #protectionLevel}: additional flag bits.
|
||||
*/
|
||||
public static final int PROTECTION_MASK_FLAGS = 0xf0;
|
||||
|
||||
/**
|
||||
* The level of access this permission is protecting, as per
|
||||
* {@link android.R.attr#protectionLevel}. Values may be
|
||||
* {@link #PROTECTION_NORMAL}, {@link #PROTECTION_DANGEROUS}, or
|
||||
* {@link #PROTECTION_SIGNATURE}. May also include the additional
|
||||
* flags {@link #PROTECTION_FLAG_SYSTEM} or {@link #PROTECTION_FLAG_DEVELOPMENT}
|
||||
* (which only make sense in combination with the base
|
||||
* {@link #PROTECTION_SIGNATURE}.
|
||||
*/
|
||||
public int protectionLevel;
|
||||
|
||||
/**
|
||||
* The group this permission is a part of, as per
|
||||
* {@link android.R.attr#permissionGroup}.
|
||||
*/
|
||||
public String group;
|
||||
|
||||
/**
|
||||
* Flag for {@link #flags}, corresponding to <code>costsMoney</code>
|
||||
* value of {@link android.R.attr#permissionFlags}.
|
||||
*/
|
||||
public static final int FLAG_COSTS_MONEY = 1<<0;
|
||||
|
||||
/**
|
||||
* Additional flags about this permission as given by
|
||||
* {@link android.R.attr#permissionFlags}.
|
||||
*/
|
||||
public int flags;
|
||||
|
||||
/**
|
||||
* A string resource identifier (in the package's resources) of this
|
||||
* permission's description. From the "description" attribute or,
|
||||
* if not set, 0.
|
||||
*/
|
||||
public int descriptionRes;
|
||||
|
||||
/**
|
||||
* The description string provided in the AndroidManifest file, if any. You
|
||||
* probably don't want to use this, since it will be null if the description
|
||||
* is in a resource. You probably want
|
||||
* {@link PermissionInfo#loadDescription} instead.
|
||||
*/
|
||||
public CharSequence nonLocalizedDescription;
|
||||
|
||||
/** @hide */
|
||||
public static int fixProtectionLevel(int level) {
|
||||
if (level == PROTECTION_SIGNATURE_OR_SYSTEM) {
|
||||
level = PROTECTION_SIGNATURE | PROTECTION_FLAG_SYSTEM;
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public static String protectionToString(int level) {
|
||||
String protLevel = "????";
|
||||
switch (level&PROTECTION_MASK_BASE) {
|
||||
case PermissionInfo.PROTECTION_DANGEROUS:
|
||||
protLevel = "dangerous";
|
||||
break;
|
||||
case PermissionInfo.PROTECTION_NORMAL:
|
||||
protLevel = "normal";
|
||||
break;
|
||||
case PermissionInfo.PROTECTION_SIGNATURE:
|
||||
protLevel = "signature";
|
||||
break;
|
||||
case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM:
|
||||
protLevel = "signatureOrSystem";
|
||||
break;
|
||||
}
|
||||
if ((level&PermissionInfo.PROTECTION_FLAG_SYSTEM) != 0) {
|
||||
protLevel += "|system";
|
||||
}
|
||||
if ((level&PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) {
|
||||
protLevel += "|development";
|
||||
}
|
||||
return protLevel;
|
||||
}
|
||||
|
||||
public PermissionInfo() {
|
||||
}
|
||||
|
||||
public PermissionInfo(PermissionInfo orig) {
|
||||
super(orig);
|
||||
protectionLevel = orig.protectionLevel;
|
||||
flags = orig.flags;
|
||||
group = orig.group;
|
||||
descriptionRes = orig.descriptionRes;
|
||||
nonLocalizedDescription = orig.nonLocalizedDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the textual description of this permission. This
|
||||
* will call back on the given PackageManager to load the description from
|
||||
* the application.
|
||||
*
|
||||
* @param pm A PackageManager from which the label can be loaded; usually
|
||||
* the PackageManager from which you originally retrieved this item.
|
||||
*
|
||||
* @return Returns a CharSequence containing the permission's description.
|
||||
* If there is no description, null is returned.
|
||||
*/
|
||||
public CharSequence loadDescription(PackageManager pm) {
|
||||
if (nonLocalizedDescription != null) {
|
||||
return nonLocalizedDescription;
|
||||
}
|
||||
if (descriptionRes != 0) {
|
||||
CharSequence label = pm.getText(packageName, descriptionRes, null);
|
||||
if (label != null) {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "PermissionInfo{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " " + name + "}";
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
127
src/api-impl/android/content/pm/ProviderInfo.java
Normal file
127
src/api-impl/android/content/pm/ProviderInfo.java
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
import android.os.PatternMatcher;
|
||||
import android.util.Printer;
|
||||
|
||||
/**
|
||||
* Holds information about a specific
|
||||
* {@link android.content.ContentProvider content provider}. This is returned by
|
||||
* {@link android.content.pm.PackageManager#resolveContentProvider(java.lang.String, int)
|
||||
* PackageManager.resolveContentProvider()}.
|
||||
*/
|
||||
public final class ProviderInfo extends ComponentInfo {
|
||||
|
||||
/** The name provider is published under content:// */
|
||||
public String authority = null;
|
||||
|
||||
/** Optional permission required for read-only access this content
|
||||
* provider. */
|
||||
public String readPermission = null;
|
||||
|
||||
/** Optional permission required for read/write access this content
|
||||
* provider. */
|
||||
public String writePermission = null;
|
||||
|
||||
/** If true, additional permissions to specific Uris in this content
|
||||
* provider can be granted, as per the
|
||||
* {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
|
||||
* grantUriPermissions} attribute.
|
||||
*/
|
||||
public boolean grantUriPermissions = false;
|
||||
|
||||
/**
|
||||
* If non-null, these are the patterns that are allowed for granting URI
|
||||
* permissions. Any URI that does not match one of these patterns will not
|
||||
* allowed to be granted. If null, all URIs are allowed. The
|
||||
* {@link PackageManager#GET_URI_PERMISSION_PATTERNS
|
||||
* PackageManager.GET_URI_PERMISSION_PATTERNS} flag must be specified for
|
||||
* this field to be filled in.
|
||||
*/
|
||||
public PatternMatcher[] uriPermissionPatterns = null;
|
||||
|
||||
/**
|
||||
* If non-null, these are path-specific permissions that are allowed for
|
||||
* accessing the provider. Any permissions listed here will allow a
|
||||
* holding client to access the provider, and the provider will check
|
||||
* the URI it provides when making calls against the patterns here.
|
||||
*/
|
||||
public PathPermission[] pathPermissions = null;
|
||||
|
||||
/** If true, this content provider allows multiple instances of itself
|
||||
* to run in different process. If false, a single instances is always
|
||||
* run in {@link #processName}. */
|
||||
public boolean multiprocess = false;
|
||||
|
||||
/** Used to control initialization order of single-process providers
|
||||
* running in the same process. Higher goes first. */
|
||||
public int initOrder = 0;
|
||||
|
||||
/**
|
||||
* Bit in {@link #flags}: If set, a single instance of the provider will
|
||||
* run for all users on the device. Set from the
|
||||
* {@link android.R.attr#singleUser} attribute.
|
||||
*/
|
||||
public static final int FLAG_SINGLE_USER = 0x40000000;
|
||||
|
||||
/**
|
||||
* Options that have been set in the provider declaration in the
|
||||
* manifest.
|
||||
* These include: {@link #FLAG_SINGLE_USER}.
|
||||
*/
|
||||
public int flags = 0;
|
||||
|
||||
/**
|
||||
* Whether or not this provider is syncable.
|
||||
* @deprecated This flag is now being ignored. The current way to make a provider
|
||||
* syncable is to provide a SyncAdapter service for a given provider/account type.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isSyncable = false;
|
||||
|
||||
public ProviderInfo() {
|
||||
}
|
||||
|
||||
public ProviderInfo(ProviderInfo orig) {
|
||||
super(orig);
|
||||
authority = orig.authority;
|
||||
readPermission = orig.readPermission;
|
||||
writePermission = orig.writePermission;
|
||||
grantUriPermissions = orig.grantUriPermissions;
|
||||
uriPermissionPatterns = orig.uriPermissionPatterns;
|
||||
pathPermissions = orig.pathPermissions;
|
||||
multiprocess = orig.multiprocess;
|
||||
initOrder = orig.initOrder;
|
||||
flags = orig.flags;
|
||||
isSyncable = orig.isSyncable;
|
||||
}
|
||||
|
||||
public void dump(Printer pw, String prefix) {
|
||||
super.dumpFront(pw, prefix);
|
||||
pw.println(prefix + "authority=" + authority);
|
||||
pw.println(prefix + "flags=0x" + Integer.toHexString(flags));
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ContentProviderInfo{name=" + authority + " className=" + name + "}";
|
||||
}
|
||||
}
|
||||
88
src/api-impl/android/content/pm/ServiceInfo.java
Normal file
88
src/api-impl/android/content/pm/ServiceInfo.java
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
import android.util.Printer;
|
||||
|
||||
/**
|
||||
* Information you can retrieve about a particular application
|
||||
* service. This corresponds to information collected from the
|
||||
* AndroidManifest.xml's <service> tags.
|
||||
*/
|
||||
public class ServiceInfo extends ComponentInfo {
|
||||
/**
|
||||
* Optional name of a permission required to be able to access this
|
||||
* Service. From the "permission" attribute.
|
||||
*/
|
||||
public String permission;
|
||||
|
||||
/**
|
||||
* Bit in {@link #flags}: If set, the service will automatically be
|
||||
* stopped by the system if the user removes a task that is rooted
|
||||
* in one of the application's activities. Set from the
|
||||
* {@link android.R.attr#stopWithTask} attribute.
|
||||
*/
|
||||
public static final int FLAG_STOP_WITH_TASK = 0x0001;
|
||||
|
||||
/**
|
||||
* Bit in {@link #flags}: If set, the service will run in its own
|
||||
* isolated process. Set from the
|
||||
* {@link android.R.attr#isolatedProcess} attribute.
|
||||
*/
|
||||
public static final int FLAG_ISOLATED_PROCESS = 0x0002;
|
||||
|
||||
/**
|
||||
* Bit in {@link #flags}: If set, a single instance of the service will
|
||||
* run for all users on the device. Set from the
|
||||
* {@link android.R.attr#singleUser} attribute.
|
||||
*/
|
||||
public static final int FLAG_SINGLE_USER = 0x40000000;
|
||||
|
||||
/**
|
||||
* Options that have been set in the service declaration in the
|
||||
* manifest.
|
||||
* These include:
|
||||
* {@link #FLAG_STOP_WITH_TASK}, {@link #FLAG_ISOLATED_PROCESS},
|
||||
* {@link #FLAG_SINGLE_USER}.
|
||||
*/
|
||||
public int flags;
|
||||
|
||||
public ServiceInfo() {
|
||||
}
|
||||
|
||||
public ServiceInfo(ServiceInfo orig) {
|
||||
super(orig);
|
||||
permission = orig.permission;
|
||||
flags = orig.flags;
|
||||
}
|
||||
|
||||
public void dump(Printer pw, String prefix) {
|
||||
super.dumpFront(pw, prefix);
|
||||
pw.println(prefix + "permission=" + permission);
|
||||
pw.println(prefix + "flags=0x" + Integer.toHexString(flags));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ServiceInfo{"
|
||||
+ Integer.toHexString(System.identityHashCode(this))
|
||||
+ " " + name + "}";
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
190
src/api-impl/android/content/pm/Signature.java
Normal file
190
src/api-impl/android/content/pm/Signature.java
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.security.PublicKey;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Opaque, immutable representation of a signature associated with an
|
||||
* application package.
|
||||
*/
|
||||
public class Signature {
|
||||
private final byte[] mSignature;
|
||||
private int mHashCode;
|
||||
private boolean mHaveHashCode;
|
||||
private SoftReference<String> mStringRef;
|
||||
|
||||
/**
|
||||
* Create Signature from an existing raw byte array.
|
||||
*/
|
||||
public Signature(byte[] signature) {
|
||||
mSignature = signature.clone();
|
||||
}
|
||||
|
||||
private static final int parseHexDigit(int nibble) {
|
||||
if ('0' <= nibble && nibble <= '9') {
|
||||
return nibble - '0';
|
||||
} else if ('a' <= nibble && nibble <= 'f') {
|
||||
return nibble - 'a' + 10;
|
||||
} else if ('A' <= nibble && nibble <= 'F') {
|
||||
return nibble - 'A' + 10;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid character " + nibble + " in hex string");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Signature from a text representation previously returned by
|
||||
* {@link #toChars} or {@link #toCharsString()}. Signatures are expected to
|
||||
* be a hex-encoded ASCII string.
|
||||
*
|
||||
* @param text hex-encoded string representing the signature
|
||||
* @throws IllegalArgumentException when signature is odd-length
|
||||
*/
|
||||
public Signature(String text) {
|
||||
final byte[] input = text.getBytes();
|
||||
final int N = input.length;
|
||||
|
||||
if (N % 2 != 0) {
|
||||
throw new IllegalArgumentException("text size " + N + " is not even");
|
||||
}
|
||||
|
||||
final byte[] sig = new byte[N / 2];
|
||||
int sigIndex = 0;
|
||||
|
||||
for (int i = 0; i < N;) {
|
||||
final int hi = parseHexDigit(input[i++]);
|
||||
final int lo = parseHexDigit(input[i++]);
|
||||
sig[sigIndex++] = (byte) ((hi << 4) | lo);
|
||||
}
|
||||
|
||||
mSignature = sig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the Signature as ASCII text.
|
||||
*/
|
||||
public char[] toChars() {
|
||||
return toChars(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the Signature as ASCII text in to an existing array.
|
||||
*
|
||||
* @param existingArray Existing char array or null.
|
||||
* @param outLen Output parameter for the number of characters written in
|
||||
* to the array.
|
||||
* @return Returns either <var>existingArray</var> if it was large enough
|
||||
* to hold the ASCII representation, or a newly created char[] array if
|
||||
* needed.
|
||||
*/
|
||||
public char[] toChars(char[] existingArray, int[] outLen) {
|
||||
byte[] sig = mSignature;
|
||||
final int N = sig.length;
|
||||
final int N2 = N*2;
|
||||
char[] text = existingArray == null || N2 > existingArray.length
|
||||
? new char[N2] : existingArray;
|
||||
for (int j=0; j<N; j++) {
|
||||
byte v = sig[j];
|
||||
int d = (v>>4)&0xf;
|
||||
text[j*2] = (char)(d >= 10 ? ('a' + d - 10) : ('0' + d));
|
||||
d = v&0xf;
|
||||
text[j*2+1] = (char)(d >= 10 ? ('a' + d - 10) : ('0' + d));
|
||||
}
|
||||
if (outLen != null) outLen[0] = N;
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the result of {@link #toChars()} as a String.
|
||||
*/
|
||||
public String toCharsString() {
|
||||
String str = mStringRef == null ? null : mStringRef.get();
|
||||
if (str != null) {
|
||||
return str;
|
||||
}
|
||||
str = new String(toChars());
|
||||
mStringRef = new SoftReference<String>(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the contents of this signature as a byte array.
|
||||
*/
|
||||
public byte[] toByteArray() {
|
||||
byte[] bytes = new byte[mSignature.length];
|
||||
System.arraycopy(mSignature, 0, bytes, 0, mSignature.length);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public key for this signature.
|
||||
*
|
||||
* @throws CertificateException when Signature isn't a valid X.509
|
||||
* certificate; shouldn't happen.
|
||||
* @hide
|
||||
*/
|
||||
public PublicKey getPublicKey() throws CertificateException {
|
||||
final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
|
||||
final ByteArrayInputStream bais = new ByteArrayInputStream(mSignature);
|
||||
final Certificate cert = certFactory.generateCertificate(bais);
|
||||
return cert.getPublicKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
try {
|
||||
if (obj != null) {
|
||||
Signature other = (Signature)obj;
|
||||
return this == other || Arrays.equals(mSignature, other.mSignature);
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (mHaveHashCode) {
|
||||
return mHashCode;
|
||||
}
|
||||
mHashCode = Arrays.hashCode(mSignature);
|
||||
mHaveHashCode = true;
|
||||
return mHashCode;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given {@link Signature} sets are exactly equal.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static boolean areExactMatch(Signature[] a, Signature[] b) {
|
||||
return ArrayUtils.containsAll(a, b) && ArrayUtils.containsAll(b, a);
|
||||
}
|
||||
}
|
||||
57
src/api-impl/android/content/pm/VerifierInfo.java
Normal file
57
src/api-impl/android/content/pm/VerifierInfo.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.content.pm;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
/**
|
||||
* Contains information about a package verifier as used by
|
||||
* {@code PackageManagerService} during package verification.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class VerifierInfo {
|
||||
/** Package name of the verifier. */
|
||||
public final String packageName;
|
||||
|
||||
/** Signatures used to sign the package verifier's package. */
|
||||
public final PublicKey publicKey;
|
||||
|
||||
/**
|
||||
* Creates an object that represents a verifier info object.
|
||||
*
|
||||
* @param packageName the package name in Java-style. Must not be {@code
|
||||
* null} or empty.
|
||||
* @param publicKey the public key for the signer encoded in Base64. Must
|
||||
* not be {@code null} or empty.
|
||||
* @throws IllegalArgumentException if either argument is null or empty.
|
||||
*/
|
||||
public VerifierInfo(String packageName, PublicKey publicKey) {
|
||||
if (packageName == null || packageName.length() == 0) {
|
||||
throw new IllegalArgumentException("packageName must not be null or empty");
|
||||
} else if (publicKey == null) {
|
||||
throw new IllegalArgumentException("publicKey must not be null");
|
||||
}
|
||||
|
||||
this.packageName = packageName;
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user