use of android.content.pm.Signature in project android_frameworks_base by ResurrectionRemix.
the class NetworkPolicyManagerServiceTest method _setUp.
public void _setUp() throws Exception {
super.setUp();
setCurrentTimeMillis(TEST_START);
// intercept various broadcasts, and pretend that uids have packages
mServiceContext = new BroadcastInterceptingContext(getContext()) {
@Override
public PackageManager getPackageManager() {
return new MockPackageManager() {
@Override
public String[] getPackagesForUid(int uid) {
return new String[] { "com.example" };
}
@Override
public PackageInfo getPackageInfo(String packageName, int flags) {
final PackageInfo info = new PackageInfo();
final Signature signature;
if ("android".equals(packageName)) {
signature = new Signature("F00D");
} else {
signature = new Signature("DEAD");
}
info.signatures = new Signature[] { signature };
return info;
}
};
}
@Override
public void startActivity(Intent intent) {
// ignored
}
};
mPolicyDir = getContext().getFilesDir();
if (mPolicyDir.exists()) {
IoUtils.deleteContents(mPolicyDir);
}
mActivityManager = createMock(IActivityManager.class);
mStatsService = createMock(INetworkStatsService.class);
mNetworkManager = createMock(INetworkManagementService.class);
mPolicyListener = createMock(INetworkPolicyListener.class);
mTime = createMock(TrustedTime.class);
mConnManager = createMock(IConnectivityManager.class);
mNotifManager = createMock(INotificationManager.class);
mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager, mStatsService, mNetworkManager, mTime, mPolicyDir, true);
mService.bindConnectivityManager(mConnManager);
mService.bindNotificationManager(mNotifManager);
// RemoteCallbackList needs a binder to use as key
expect(mPolicyListener.asBinder()).andReturn(mStubBinder).atLeastOnce();
replay();
mService.registerListener(mPolicyListener);
verifyAndReset();
// catch IProcessObserver during systemReady()
final Capture<IProcessObserver> processObserver = new Capture<IProcessObserver>();
mActivityManager.registerProcessObserver(capture(processObserver));
expectLastCall().atLeastOnce();
// catch INetworkManagementEventObserver during systemReady()
final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
mNetworkManager.registerObserver(capture(networkObserver));
expectLastCall().atLeastOnce();
expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
expectCurrentTime();
replay();
mService.systemReady();
verifyAndReset();
mProcessObserver = processObserver.getValue();
mNetworkObserver = networkObserver.getValue();
}
use of android.content.pm.Signature in project android_frameworks_base by ResurrectionRemix.
the class AccountManagerService method calculatePackageSignatureDigest.
private byte[] calculatePackageSignatureDigest(String callerPkg) {
MessageDigest digester;
try {
digester = MessageDigest.getInstance("SHA-256");
PackageInfo pkgInfo = mPackageManager.getPackageInfo(callerPkg, PackageManager.GET_SIGNATURES);
for (Signature sig : pkgInfo.signatures) {
digester.update(sig.toByteArray());
}
} catch (NoSuchAlgorithmException x) {
Log.wtf(TAG, "SHA-256 should be available", x);
digester = null;
} catch (NameNotFoundException e) {
Log.w(TAG, "Could not find packageinfo for: " + callerPkg);
digester = null;
}
return (digester == null) ? null : digester.digest();
}
use of android.content.pm.Signature in project android_frameworks_base by ResurrectionRemix.
the class BackupUtilsTest method testHashSignature.
public void testHashSignature() {
final byte[] sig1 = "abc".getBytes();
final byte[] sig2 = "def".getBytes();
final byte[] hash1a = BackupUtils.hashSignature(sig1);
final byte[] hash1b = BackupUtils.hashSignature(new Signature(sig1));
final byte[] hash2a = BackupUtils.hashSignature(sig2);
final byte[] hash2b = BackupUtils.hashSignature(new Signature(sig2));
assertEquals(32, hash1a.length);
MoreAsserts.assertEquals(hash1a, hash1b);
assertEquals(32, hash2a.length);
MoreAsserts.assertEquals(hash2a, hash2b);
assertFalse(Arrays.equals(hash1a, hash2a));
final ArrayList<byte[]> listA = BackupUtils.hashSignatureArray(Arrays.asList("abc".getBytes(), "def".getBytes()));
final ArrayList<byte[]> listB = BackupUtils.hashSignatureArray(new Signature[] { new Signature("abc".getBytes()), new Signature("def".getBytes()) });
assertEquals(2, listA.size());
assertEquals(2, listB.size());
MoreAsserts.assertEquals(hash1a, listA.get(0));
MoreAsserts.assertEquals(hash1a, listB.get(0));
MoreAsserts.assertEquals(hash2a, listA.get(1));
MoreAsserts.assertEquals(hash2a, listB.get(1));
}
use of android.content.pm.Signature in project android_frameworks_base by ResurrectionRemix.
the class Utils method getCertFingerprintsFromPackageManager.
/**
* Returns the normalized sha-256 fingerprints of a given package according to the Android
* package manager.
*/
public static List<String> getCertFingerprintsFromPackageManager(String packageName, Context context) throws NameNotFoundException {
Signature[] signatures = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures;
ArrayList<String> result = new ArrayList<String>(signatures.length);
for (Signature sig : signatures) {
result.add(computeNormalizedSha256Fingerprint(sig.toByteArray()));
}
return result;
}
use of android.content.pm.Signature in project DroidPlugin by DroidPluginTeam.
the class IPluginManagerImpl method loadAllPlugin.
private void loadAllPlugin(Context context) {
long b = System.currentTimeMillis();
ArrayList<File> apkfiles = null;
try {
apkfiles = new ArrayList<File>();
File baseDir = new File(PluginDirHelper.getBaseDir(context));
File[] dirs = baseDir.listFiles();
for (File dir : dirs) {
if (dir.isDirectory()) {
File file = new File(dir, "apk/base-1.apk");
if (file.exists()) {
apkfiles.add(file);
}
}
}
} catch (Exception e) {
Log.e(TAG, "scan a apk file error", e);
}
Log.i(TAG, "Search apk cost %s ms", (System.currentTimeMillis() - b));
b = System.currentTimeMillis();
if (apkfiles != null && apkfiles.size() > 0) {
for (File pluginFile : apkfiles) {
long b1 = System.currentTimeMillis();
try {
PluginPackageParser pluginPackageParser = new PluginPackageParser(mContext, pluginFile);
Signature[] signatures = readSignatures(pluginPackageParser.getPackageName());
if (signatures == null || signatures.length <= 0) {
pluginPackageParser.collectCertificates(0);
PackageInfo info = pluginPackageParser.getPackageInfo(PackageManager.GET_SIGNATURES);
saveSignatures(info);
} else {
mSignatureCache.put(pluginPackageParser.getPackageName(), signatures);
pluginPackageParser.writeSignature(signatures);
}
if (!mPluginCache.containsKey(pluginPackageParser.getPackageName())) {
mPluginCache.put(pluginPackageParser.getPackageName(), pluginPackageParser);
}
} catch (Throwable e) {
Log.e(TAG, "parse a apk file error %s", e, pluginFile.getPath());
} finally {
Log.i(TAG, "Parse %s apk cost %s ms", pluginFile.getPath(), (System.currentTimeMillis() - b1));
}
}
}
Log.i(TAG, "Parse all apk cost %s ms", (System.currentTimeMillis() - b));
b = System.currentTimeMillis();
try {
mActivityManagerService.onCreate(IPluginManagerImpl.this);
} catch (Throwable e) {
Log.e(TAG, "mActivityManagerService.onCreate", e);
}
Log.i(TAG, "ActivityManagerService.onCreate %s ms", (System.currentTimeMillis() - b));
}
Aggregations