date:2021-09-30 18:26:58

This commit is contained in:
2021-09-30 18:27:13 +08:00
parent 81147b61f8
commit 2884e4924e
10 changed files with 449 additions and 39 deletions

View File

@@ -1,22 +1,36 @@
package com.tt.activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.net.Uri;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
import android.provider.MediaStore;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.info.sn.IGetInfoInterface;
import com.jiaoguanyi.appstore.IGetLicenseInterface;
import com.notepad.uiui.INoteAidlInterface;
import com.tt.base.BaseActivity;
import com.tt.ttutils.R;
import com.tt.ttutils.java.ApkUtils;
import com.tt.ttutils.java.ToastUtil;
import com.tt.ttutils.jni.NDKTools;
import java.lang.annotation.Native;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -24,6 +38,16 @@ import butterknife.ButterKnife;
public class JMainActivity extends BaseActivity {
@BindView(R.id.textView)
TextView textView;
@BindView(R.id.button)
Button button;
private ServiceConnection mServiceConnection;
private INoteAidlInterface noteAidlInterface;
private ServiceConnection mLicenseServiceConnection;
private IGetLicenseInterface getLicenseInterface;
private ServiceConnection mIGetInfoConnection;
private IGetInfoInterface getInfoInterface;
private String TAG = JMainActivity.class.getSimpleName();
@Override
protected int setLayoutResourceID() {
@@ -46,18 +70,230 @@ public class JMainActivity extends BaseActivity {
@Override
protected void initData() {
registHideAppReceiver();
registForbidAppReceiver();
registerUserInfoReceiver();
String ndks = NDKTools.getStringFromNDK();
mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
noteAidlInterface = INoteAidlInterface.Stub.asInterface(iBinder);
Log.e(TAG, "onServiceConnected: ");
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
Log.e(TAG, "onServiceDisconnected: ");
noteAidlInterface = null;
// Intent intent = new Intent();
// intent.setComponent(new ComponentName("com.notepad.uiui", "com.notepad.uiui.service.NoteService"));
// startService(intent);
}
};
mLicenseServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
getLicenseInterface = IGetLicenseInterface.Stub.asInterface(service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
getLicenseInterface = null;
}
};
mIGetInfoConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.e(TAG, "onServiceConnected: mIGetInfoConnection");
getInfoInterface = IGetInfoInterface.Stub.asInterface(service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.e(TAG, "onServiceDisconnected: mIGetInfoConnection");
getInfoInterface = null;
bindinfoService();
}
};
bindService();
bindLicenseService();
bindinfoService();
// Intent intent2 = new Intent();
// intent2.setComponent(new ComponentName("com.info.sn", "com.notepad.uiui.service.NoteService"));
// startService(intent2);
// Intent intent = new Intent();
// intent.setComponent(new ComponentName("com.notepad.uiui", "com.notepad.uiui.service.NoteService"));
// startService(intent);
textView.setText(ndks);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
open();
// open();
bindService();
try {
if (noteAidlInterface == null) {
bindService();
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.notepad.uiui", "com.notepad.uiui.service.NoteService"));
startService(intent);
return;
}
Log.e(TAG, "onClick: " + noteAidlInterface);
String test = noteAidlInterface.getNote();
Log.e(TAG, "onClick: " + test);
} catch (RemoteException e) {
// e.printStackTrace();
Log.e(TAG, "onClick: " + e.getMessage());
}
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// ApkUtils.openApp(JMainActivity.this, "com.info.sn");
if (getInfoInterface != null) {
try {
String userInfo = getInfoInterface.getUserInfo();
Log.e("mIGetInfoConnection", "getUserInfo: " + userInfo);
List<String> hideAPP = getInfoInterface.getHideAPP();
Log.e("mIGetInfoConnection", "getHideAPP: " + hideAPP);
List<String> forbidAPP = getInfoInterface.getForbidAPP();
Log.e("mIGetInfoConnection", "getForbidAPP: " + forbidAPP);
textView.setText(userInfo);
} catch (RemoteException e) {
e.printStackTrace();
Log.e("mIGetInfoConnection", "getUserInfo: " + e.getMessage());
}
}else {
bindinfoService();
}
// if (getLicenseInterface != null) {
// try {
// String license = getLicenseInterface.getLicense();
// Log.e(TAG, "onClick: " + license);
// textView.setText(license);
// } catch (RemoteException e) {
// e.printStackTrace();
// Log.e(TAG, "onClick: " + e.getMessage());
// }
// }
}
});
}
private HideAppReceiver hideAppReceiver;
private void registHideAppReceiver() {
if (hideAppReceiver == null) {
hideAppReceiver = new HideAppReceiver();
}
IntentFilter filter = new IntentFilter();
filter.addAction("UPDATE_HIDE_APP");
registerReceiver(hideAppReceiver, filter);
}
private class HideAppReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "onReceive: " + intent.getAction());
ArrayList<String> appList = intent.getStringArrayListExtra("hide_app_list");
if (appList != null) {
Log.e(TAG, "onReceive: " + appList);
}
}
}
private ForbidAppReceiver forbidAppReceiver;
private void registForbidAppReceiver() {
if (forbidAppReceiver == null) {
forbidAppReceiver = new ForbidAppReceiver();
}
IntentFilter filter = new IntentFilter();
filter.addAction("UPDATE_FORBID_APP");
registerReceiver(forbidAppReceiver, filter);
}
private class ForbidAppReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "onReceive: " + intent.getAction());
ArrayList<String> appList = intent.getStringArrayListExtra("forbid_app_list");
if (appList != null) {
Log.e(TAG, "onReceive: " + appList);
}
}
}
private static final String UPDATE_USER_INFO = "UPDATE_USER_INFO";
private UserInfoReceiver userInfoReceiver;
private void registerUserInfoReceiver() {
if (userInfoReceiver == null) {
userInfoReceiver = new UserInfoReceiver();
}
IntentFilter filter = new IntentFilter();
filter.addAction(UPDATE_USER_INFO);
registerReceiver(userInfoReceiver, filter);
}
private class UserInfoReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "onReceive: " + intent.getAction());
String userInfo = intent.getStringExtra("user_info");
Log.e(TAG, "onReceive: " + userInfo);
}
}
private void bindService() {
if (noteAidlInterface == null) {
//这是连接aidl服务的代码
Intent intent = new Intent();
intent.setAction("com.notepad.uiui.INoteAidlInterface");
intent.setPackage("com.notepad.uiui");
intent.setComponent(new ComponentName("com.notepad.uiui", "com.notepad.uiui.service.NoteService"));
bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
}
}
private void bindLicenseService() {
if (getLicenseInterface == null) {
//这是连接aidl服务的代码
Intent intent = new Intent();
intent.setAction("com.jiaoguanyi.appstore.IGetLicenseInterface");
intent.setPackage("com.jiaoguanyi.appstore");
intent.setComponent(new ComponentName("com.jiaoguanyi.appstore", "com.mjsheng.myappstore.service.RemoteService"));
bindService(intent, mLicenseServiceConnection, Context.BIND_AUTO_CREATE);
}
}
private void bindinfoService() {
if (getInfoInterface == null) {
//这是连接aidl服务的代码
Intent intent = new Intent();
intent.setAction("com.info.sn.IGetInfoInterface");
intent.setPackage("com.info.sn");
intent.setComponent(new ComponentName("com.info.sn", "com.info.sn.service.RemoteService"));
bindService(intent, mIGetInfoConnection, Context.BIND_AUTO_CREATE);
}
}
// 用来计算返回键的点击间隔时间
private long exitTime = 0;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK
@@ -74,7 +310,8 @@ public class JMainActivity extends BaseActivity {
return super.onKeyDown(keyCode, event);
}
private long mPreClickTime=0;
private long mPreClickTime = 0;
private void lazyExit() {
if (System.currentTimeMillis() - mPreClickTime > 1000) {
@@ -101,4 +338,5 @@ public class JMainActivity extends BaseActivity {
startActivityForResult(intent, 1);
}
}
}

View File

@@ -1,21 +1,32 @@
package com.tt.activity
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle
import android.os.Environment
import android.os.IBinder
import android.util.Log
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.notepad.uiui.INoteAidlInterface
import com.tt.ttutils.R
import com.tt.ttutils.java.DevicesUtils
import kotlinx.android.synthetic.main.activity_main.*
import me.jessyan.autosize.internal.CancelAdapt
import java.io.File
import kotlin.math.log
class MainActivity : AppCompatActivity(), CancelAdapt {
lateinit var button: Button
private val INSTALLAPK_ACTION = "JGY_INSTALLAPK_ACTION"
private val INSTALLAPK_PREMISSIONS = "com.jiaoguanyi.appstore.permissions.INSTALL_APK"
lateinit var filePath:String
lateinit var filePath: String
lateinit var mServiceConnection: ServiceConnection
lateinit var noteAidlInterface: INoteAidlInterface
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@@ -25,12 +36,35 @@ class MainActivity : AppCompatActivity(), CancelAdapt {
filePath =
Environment.getExternalStorageDirectory().absolutePath + File.separator + "Android_8.8.0.5420_537068981.apk"
button = findViewById(R.id.button)
button.setOnClickListener {
val intent = Intent(INSTALLAPK_ACTION)
intent.putExtra("packageName", "com.tencent.mobileqq")
intent.putExtra("filePath", filePath)
sendBroadcast(intent, INSTALLAPK_PREMISSIONS)
// button.setOnClickListener {
// //教管壹静默安装代码
// val intent = Intent(INSTALLAPK_ACTION)
// intent.putExtra("packageName", "com.tencent.mobileqq")
// intent.putExtra("filePath", filePath)
// sendBroadcast(intent, INSTALLAPK_PREMISSIONS)
// }
mServiceConnection = object : ServiceConnection {
override fun onServiceConnected(
componentName: ComponentName,
iBinder: IBinder
) {
noteAidlInterface = INoteAidlInterface.Stub.asInterface(iBinder)
}
override fun onServiceDisconnected(componentName: ComponentName) {
}
}
val intent = Intent("com.notepad.uiui.INoteAidlInterface")
intent.setPackage("com.notepad.uiui")
bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE)
button.setOnClickListener {
val test = noteAidlInterface.note
Log.e("test", test)
}
}

View File

@@ -1,5 +1,15 @@
package com.tt.ttutils.java;
import android.content.Context;
import android.content.Intent;
public class ApkUtils {
public static void openApp(Context context, String packageName) {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (intent != null) {
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}