Skip to content

Commit

Permalink
add feature for get app info
Browse files Browse the repository at this point in the history
  • Loading branch information
maoruibin committed Dec 25, 2016
1 parent 9b407cc commit 2d54584
Show file tree
Hide file tree
Showing 23 changed files with 636 additions and 33 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def releaseTime() {

android {
compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)
buildToolsVersion '23.0.2'
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

defaultConfig {
applicationId project.GROUP
Expand Down Expand Up @@ -161,6 +161,7 @@ dependencies {
//A small Android library to manage one-off operations.
compile 'com.jonathanfinerty.once:once:1.0.3'
compile project(':library')
compile 'com.github.maoruibin:ViewController:0.9.0'
}

task showMeCache << {
Expand Down
27 changes: 15 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.gudong.appkit"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest package="com.gudong.appkit"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- 往sdcard中写入数据的权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Expand All @@ -13,19 +12,18 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
tools:ignore="ProtectedPermissions"/>

<application
android:name=".App"
android:allowBackup="true"
android:label="@string/app_name"
tools:replace="label"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme_AppPlus">
android:theme="@style/Theme_AppPlus"
tools:replace="label">

<!-- begin umeng -->
<meta-data
Expand All @@ -48,7 +46,8 @@
<activity android:name=".ui.activity.MainActivity"/>
<activity android:name=".ui.activity.SimpleContainerActivity">
</activity>
<activity android:name=".ui.activity.SplashActivity"
<activity
android:name=".ui.activity.SplashActivity"
android:theme="@style/Theme_Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand All @@ -58,15 +57,19 @@
</activity>
<activity android:name=".ui.activity.SearchActivity">
</activity>
<activity android:name=".ui.activity.AppActivity"/>
<activity android:name=".ui.activity.AppOperateActivity"/>

<receiver android:name=".receiver.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>

<data android:scheme="package"/>
</intent-filter>
</receiver>

<activity android:name=".ui.activity.AppInfoActivity">
</activity>
</application>

</manifest>
</manifest>
51 changes: 51 additions & 0 deletions app/src/main/java/com/gudong/appkit/adapter/AppInfoAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.gudong.appkit.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

/**
* Created by GuDong on 2016/12/25 18:53.
* Contact with [email protected].
*/

public class AppInfoAdapter extends RecyclerView.Adapter<AppInfoListAdapter.ViewHolder> {
final static int TYPE_BASIC = 0;
final static int TYPE_PERMISSION = 1;
final static int TYPE_ACTIVITY = 2;

@Override
public AppInfoListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return null;
}

@Override
public void onBindViewHolder(AppInfoListAdapter.ViewHolder holder, int position) {

}

@Override
public int getItemViewType(int position) {
switch (position){
case 0:
return TYPE_BASIC;
case 1:
return TYPE_PERMISSION;
case 2:
return TYPE_ACTIVITY;
}
return super.getItemViewType(position);
}

@Override
public int getItemCount() {
return 0;
}

static class ViewHolder extends RecyclerView.ViewHolder{

public ViewHolder(View itemView) {
super(itemView);
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/gudong/appkit/dao/AppDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.gudong.appkit.dao;

import com.jaredrummler.apkparser.model.UseFeature;

import java.util.List;

/**
* Created by GuDong on 2016/12/25 19:10.
* Contact with [email protected].
*/

public class AppDetail {
public AppEntity entity;
List<UseFeature> usesFeatures;
List<String> requestedPermissions;
}
17 changes: 17 additions & 0 deletions app/src/main/java/com/gudong/appkit/dao/AppMetaCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.gudong.appkit.dao;

/**
* Created by GuDong on 2016/12/25 21:18.
* Contact with [email protected].
*/

public class AppMetaCompat extends AppEntity {
public AppEntity appEntity;
public String maxSdkVersion;
public String minSdkVersion;
public String targetSdkVersion;
public String installLocation;
public AppMetaCompat(AppEntity entity ){
this.appEntity = entity;
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/gudong/appkit/dao/WeChatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -155,6 +156,9 @@ public List<File> listTencentDownloads() {
}
if (wechatDownload.exists()) {
File[] originList = wechatDownload.listFiles();
if(originList == null){
return Collections.EMPTY_LIST;
}
List<File> apkList = new ArrayList<>();
for (File file : originList) {
if (file.getName().contains("apk")) {
Expand Down
104 changes: 104 additions & 0 deletions app/src/main/java/com/gudong/appkit/ui/activity/AppInfoActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.gudong.appkit.ui.activity;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.gudong.appkit.R;
import com.gudong.appkit.dao.AppEntity;
import com.gudong.appkit.dao.AppMetaCompat;
import com.gudong.appkit.dao.DataHelper;
import com.gudong.appkit.ui.controller.AppComponentViewController;
import com.gudong.appkit.ui.controller.AppBasicViewController;
import com.gudong.appkit.ui.controller.AppPermissionViewController;
import com.jaredrummler.apkparser.ApkParser;
import com.jaredrummler.apkparser.model.AndroidComponent;
import com.jaredrummler.apkparser.model.AndroidManifest;
import com.jaredrummler.apkparser.model.ApkMeta;
import com.jaredrummler.apkparser.model.UseFeature;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;

public class AppInfoActivity extends BaseActivity {
private LinearLayout llContainer;
private AppBasicViewController basicViewController;
private AppPermissionViewController permissionViewController;
private AppComponentViewController activityViewController;
private AppComponentViewController serviceViewController;
private AppComponentViewController receiverViewController;
private AppComponentViewController providerViewController;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initView();
basicViewController = new AppBasicViewController(this);
permissionViewController = new AppPermissionViewController(this);
activityViewController = new AppComponentViewController(this,AppComponentViewController.KEY_ACTIVITY);
serviceViewController = new AppComponentViewController(this,AppComponentViewController.KEY_SERVICE);
receiverViewController = new AppComponentViewController(this,AppComponentViewController.KEY_RECEIVER);
providerViewController = new AppComponentViewController(this,AppComponentViewController.KEY_PROVIDER);

basicViewController.attachRoot(llContainer);
permissionViewController.attachRoot(llContainer);
activityViewController.attachRoot(llContainer);

String packageName = getIntent().getStringExtra("package");
fillData(packageName);

}

private void fillData(String packageName) {
PackageManager pm = getPackageManager();
ApplicationInfo appInfo = null;
try {
appInfo = pm.getApplicationInfo(packageName, 0);
AppEntity entity = DataHelper.getAppByPackageName(packageName);
AppMetaCompat appMetaCompat = new AppMetaCompat(entity);

ApkParser apkParser = ApkParser.create(appInfo);
ApkMeta meta = apkParser.getApkMeta();
appMetaCompat.maxSdkVersion = meta.maxSdkVersion;
appMetaCompat.minSdkVersion = meta.minSdkVersion;
appMetaCompat.targetSdkVersion = meta.targetSdkVersion;
appMetaCompat.installLocation = meta.installLocation;
List<UseFeature> usesFeatures = meta.usesFeatures;
List<String> requestedPermissions = meta.usesPermissions;

AndroidManifest androidManifest = apkParser.getAndroidManifest();
List<AndroidComponent> activities = androidManifest.activities;
List<AndroidComponent> services = androidManifest.services;
List<AndroidComponent> reveivers = androidManifest.receivers;
List<AndroidComponent> providers = androidManifest.providers;

basicViewController.fillData(appMetaCompat);
permissionViewController.fillData(requestedPermissions);

activityViewController.fillData(activities);
// serviceViewController.fillData(services);
// receiverViewController.fillData(reveivers);
// providerViewController.fillData(providers);



} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}

@Override
protected int initLayout() {
return R.layout.activity_app_info;
}

private void initView() {
llContainer = (LinearLayout) findViewById(R.id.ll_container);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import com.umeng.analytics.MobclickAgent;


public class AppActivity extends BaseActivity implements View.OnClickListener {
public class AppOperateActivity extends BaseActivity implements View.OnClickListener {
// View name of the header image. Used for activity scene transitions
public static final String VIEW_NAME_HEADER_IMAGE = "detail:header:image";

Expand Down Expand Up @@ -172,7 +172,8 @@ public void onClick(View v) {
MobclickAgent.onEvent(this, "action_export");
break;
case R.id.tv_detail:
NavigationManager.openAppDetail(this,mAppEntity.getPackageName());
// NavigationManager.openAppDetail(this,mAppEntity.getPackageName());
NavigationManager.openAppInfo(this,mAppEntity.getPackageName());
MobclickAgent.onEvent(this, "action_detail");
break;
case R.id.tv_more:
Expand All @@ -183,39 +184,39 @@ public void onClick(View v) {
}

private void showMoreDialog() {
new AlertDialog.Builder(this)
AlertDialog dialog = new AlertDialog.Builder(this)
.setItems(R.array.more_action, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case 0:
openApp();
MobclickAgent.onEvent(AppActivity.this, "more_open");
MobclickAgent.onEvent(AppOperateActivity.this, "more_open");
break;
case 1:
uninstallApp();
MobclickAgent.onEvent(AppActivity.this, "more_uninstall");
MobclickAgent.onEvent(AppOperateActivity.this, "more_uninstall");
break;
case 2:
NavigationManager.gotoMarket(AppActivity.this,mAppEntity.getPackageName());
MobclickAgent.onEvent(AppActivity.this, "action_market");
NavigationManager.gotoMarket(AppOperateActivity.this,mAppEntity.getPackageName());
MobclickAgent.onEvent(AppOperateActivity.this, "action_market");
break;
}
}
})
.create()
.show();
.create();
dialog.show();
}

private void uninstallApp() {
if(Utils.isOwnApp(this,mAppEntity.getPackageName()))return;
NavigationManager.uninstallApp(AppActivity.this,mAppEntity.getPackageName());
NavigationManager.uninstallApp(AppOperateActivity.this,mAppEntity.getPackageName());
}

private void openApp() {
if(Utils.isOwnApp(this,mAppEntity.getPackageName()))return;
try {
NavigationManager.openApp(AppActivity.this,mAppEntity.getPackageName());
NavigationManager.openApp(AppOperateActivity.this,mAppEntity.getPackageName());
} catch (Exception e) {
e.printStackTrace();
Snackbar.make(mTvShare,String.format(getString(R.string.fail_open_app),mAppEntity.getAppName()),Snackbar.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void onClick(DialogInterface dialog, int which) {
gotoMainActivity(false);
}
})
.setCancelable(false)
.show();
}else{
gotoMainActivity(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.support.v7.app.AlertDialog;

import com.gudong.appkit.R;
import com.gudong.appkit.ui.activity.AppInfoActivity;
import com.gudong.appkit.ui.activity.MainActivity;

import java.io.File;
Expand Down Expand Up @@ -161,6 +162,13 @@ public static void openAppDetail(Context context, String packageName) {
context.startActivity(intent);
}

public static void openAppInfo(Context context, String packageName) {
Intent intent = new Intent(context,AppInfoActivity.class);
intent.putExtra("package",packageName);
context.startActivity(intent);

}

public static void gotoMainActivityFromSplashView(Activity context) {
context.startActivity(new Intent(context, MainActivity.class));
context.finish();
Expand Down
Loading

0 comments on commit 2d54584

Please sign in to comment.