Skip to content

Commit

Permalink
Adds Pop-Benchmarker module to project space (#811)
Browse files Browse the repository at this point in the history
* Initial import of benchmarker

* Minor cleanup, adding license info

* Adds package inspector module to project space

* Update display app name, package name

* Downgrading build targets to 28

* Renaming class, fixing imports

* Minor interop fixes

* Minor UX improvements to benchmarker

* Improvements to UX

* Fix to OBOE in while loop. Minor tweak to UI wording

* Removing unused code, minor cleanup

* Rename variable

* Renaming vars

* Dereferencing project constants

* Update submodule
  • Loading branch information
iambmelt committed Oct 29, 2019
1 parent 070b1fa commit 2d722cd
Show file tree
Hide file tree
Showing 51 changed files with 1,637 additions and 2 deletions.
1 change: 1 addition & 0 deletions package-inspector/.gitignore
@@ -0,0 +1 @@
/build
24 changes: 24 additions & 0 deletions package-inspector/build.gradle
@@ -0,0 +1,24 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.microsoft.shatestapp"
minSdkVersion 19
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation "androidx.appcompat:appcompat:$rootProject.ext.appCompatVersion"
}
21 changes: 21 additions & 0 deletions package-inspector/proguard-rules.pro
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
21 changes: 21 additions & 0 deletions package-inspector/src/main/AndroidManifest.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.microsoft.inspector">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.microsoft.inspector.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
@@ -0,0 +1,124 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.inspector;

import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Bundle;
import android.util.Base64;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class MainActivity extends AppCompatActivity {

private ListView mListView;
private PackageManager mPackageManager;
private List<ApplicationInfo> mApplications;

@Override
@SuppressLint("PackageManagerGetSignatures")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = findViewById(R.id.lv_apps);

mPackageManager = getPackageManager();
mApplications = mPackageManager.getInstalledApplications(PackageManager.GET_META_DATA);
Collections.sort(mApplications, new Comparator<ApplicationInfo>() {
@Override
public int compare(@NonNull final ApplicationInfo info1,
@NonNull final ApplicationInfo info2) {
return info1.packageName.compareTo(info2.packageName);
}
});

final List<String> packageNames = new ArrayList<>(mApplications.size());

for (final ApplicationInfo applicationInfo : mApplications) {
packageNames.add(applicationInfo.packageName);
}

final ArrayAdapter<String> appAdapter = new ArrayAdapter<>(
this,
android.R.layout.simple_list_item_1,
packageNames
);

mListView.setAdapter(appAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
final ApplicationInfo clickedAppInfo = mApplications.get(position);
try {
final PackageInfo packageInfo = mPackageManager.getPackageInfo(
clickedAppInfo.packageName,
PackageManager.GET_SIGNATURES
);

String packageSigningSha = "";

if (null != packageInfo
&& null != packageInfo.signatures
&& packageInfo.signatures.length > 0) {
final Signature signature = packageInfo.signatures[0];
final MessageDigest digest = MessageDigest.getInstance("SHA");
digest.update(signature.toByteArray());
packageSigningSha = Base64.encodeToString(digest.digest(), Base64.NO_WRAP);
}

new AlertDialog.Builder(MainActivity.this)
.setTitle(clickedAppInfo.packageName)
.setMessage("Certificate hash:\n" + packageSigningSha)
.setPositiveButton(
MainActivity.this.getString(R.string.dismiss),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}
).show();
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
});
}
}
@@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

0 comments on commit 2d722cd

Please sign in to comment.