├── Android.mk ├── README.md └── src ├── utils ├── AntiPiracyConstants.java └── AntiPiracyUtils.java ├── AntiPiracyInstallReceiver.java └── AntiPiracyNotifyService.java /Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | # leaving the makefile emtpy to prevent the build 4 | # system from traversing the project 5 | 6 | # Built as part of the Settings package 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AntiPiracySupport 2 | 3 | ATTN: the second iteration of this service will be renamed to ContentGuard and moved to an organization at 4 | https://github.com/ContentGuard. This version will still exist although it will be depreciated. If you'd 5 | like to get involved just ask and we will add you to the project! 6 | 7 | NOTE: 8 | Please report new piracy markets and malware to me or any of the others involved with this project. Pull 9 | requests are also welcome. For ROM developers interested in using this it makes more sense to track this 10 | project directly and then bridge into an existing package with correct perms (like settings). This way 11 | any changes made here to the blacklisted packages and improvements will reach out to everyone. 12 | 13 | COMMITS REQUIRED TO INTEGRATE:
14 | http://exodus-developers.net:8000/#/c/819/
15 | http://exodus-developers.net:8000/#/c/1018/
16 | http://exodus-developers.net:8000/#/c/1128/
17 | http://exodus-developers.net:8000/#/c/1172/ 18 | 19 | If you have any questions please feel free to contact me or any of the developers involved in ContentGuard.. 20 | Thank you for helping to support developers/themers! 21 | -------------------------------------------------------------------------------- /src/utils/AntiPiracyConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.antipiracy.support.utils; 18 | 19 | /** A constants class list for known piracy apps. Please report new piracy 20 | * apps to ROM developers deploying this code. 21 | * @author github.com/AlmightyMegadeth00 - activethrasher00@gmail.com 22 | */ 23 | public class AntiPiracyConstants { 24 | public static final boolean DEBUG = false; 25 | 26 | public static final String[] PACKAGES = { 27 | // Package names // App names 28 | "com.dimonvideo.luckypatcher", // Lucky patcher 29 | "com.chelpus.lackypatch", // Another lucky patcher 30 | "com.forpda.lp", // And another one 31 | "com.blackmartalpha", // Black Mart alpha 32 | "org.blackmart.market", // Black Mart 33 | "com.android.vending.billing.InAppBillingService.LUCK",// Lucky patcher 5.6.8 34 | "cc.madkite.freedom", // Freedom 35 | "com.allinone.free", // All-in-one Downloader 36 | "com.repodroid.app", // Get Apk Market 37 | "org.creeplays.hack", // CreeHack 38 | "com.baseappfull.fwd", // Game Hacker 39 | "com.zmapp", // Z market 40 | "com.dv.marketmod.installer", // Hacked play store that gives refunds without uninstalling the apk 41 | "org.mobilism.android" // Mobilism market 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /src/utils/AntiPiracyUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.antipiracy.support.utils; 18 | 19 | import android.app.PackageDeleteObserver; 20 | import android.content.pm.IPackageDeleteObserver; 21 | import android.content.pm.PackageManager; 22 | import android.os.RemoteException; 23 | import android.util.Log; 24 | 25 | import java.lang.reflect.Method; 26 | 27 | import static org.antipiracy.support.utils.AntiPiracyConstants.*; 28 | 29 | /** This service blocks the install of known piracy/malware apps. Please report new piracy 30 | * apps to ROM developers deploying this code. 31 | * @author github.com/AlmightyMegadeth00 - activethrasher00@gmail.com 32 | */ 33 | public class AntiPiracyUtils { 34 | static final String TAG = "ANTI-PIRACY: Utilities"; 35 | 36 | private static PackageDeleteObserver sPDO; 37 | 38 | private AntiPiracyUtils() { 39 | sPDO = getPackageDeleteObserver(); 40 | } 41 | 42 | private static Class[] UNINSTALLTYPES = new Class[] { 43 | String.class, IPackageDeleteObserver.class, int.class 44 | }; 45 | 46 | public static class PackageDeleteObserver extends IPackageDeleteObserver.Stub { 47 | public void packageDeleted(String packageName, int returnCode) throws RemoteException { 48 | if (DEBUG) Log.i(TAG, "PackageDeleteObserver: " + packageName + " removed"); 49 | } 50 | } 51 | 52 | public static PackageDeleteObserver getPackageDeleteObserver() { 53 | if (sPDO == null) sPDO = new PackageDeleteObserver(); 54 | return sPDO; 55 | } 56 | 57 | public static Method getUninstallTypes(PackageManager pm) throws NoSuchMethodException { 58 | try { 59 | return pm.getClass().getMethod("deletePackage", UNINSTALLTYPES); 60 | } catch (NoSuchMethodException WTF) { 61 | Log.e(TAG, "NoSuchMethodException" + WTF); 62 | } 63 | return null; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/AntiPiracyInstallReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.antipiracy.support; 18 | 19 | import android.app.ActivityManager; 20 | import android.app.ActivityManager.RunningServiceInfo; 21 | import android.content.BroadcastReceiver; 22 | import android.content.Context; 23 | import android.content.Intent; 24 | import android.content.pm.PackageManager; 25 | import android.content.pm.PackageManager.NameNotFoundException; 26 | import android.net.Uri; 27 | import android.os.Bundle; 28 | import android.os.Handler; 29 | import android.util.Log; 30 | import android.widget.Toast; 31 | 32 | import static org.antipiracy.support.utils.AntiPiracyConstants.*; 33 | 34 | /* 35 | * TO DO: add list of known app piracy websites and append to the host file 36 | */ 37 | 38 | /** This service blocks the install of known piracy/malware apps. Please report new piracy 39 | * apps to ROM developers deploying this code. 40 | * @author github.com/AlmightyMegadeth00 - activethrasher00@gmail.com 41 | */ 42 | public class AntiPiracyInstallReceiver extends BroadcastReceiver { 43 | private static final String TAG = "ANTI-PIRACY: Install receiver"; 44 | 45 | @Override 46 | public void onReceive(Context ctx, Intent intent) { 47 | Intent notifyService = new Intent(ctx, AntiPiracyNotifyService.class); 48 | if (DEBUG) Log.i(TAG, "install check event"); 49 | boolean displayToast = false; 50 | 51 | for (String app : PACKAGES) { 52 | if (DEBUG) Log.e(TAG, "PACKAGE " + app + " testing for install"); 53 | if (isInstalled(ctx, app)) { 54 | Log.i("(╯°□°)╯︵ ┻━┻", "Blacklisted packages found: " + app); 55 | if (!isServiceRunning(AntiPiracyNotifyService.class, ctx)) { 56 | ctx.startService(notifyService); 57 | displayToast = true; 58 | } 59 | break; 60 | } 61 | } 62 | 63 | if (displayToast) { 64 | Toast.makeText(ctx, "Anti-piracy software activated", Toast.LENGTH_LONG).show(); 65 | } 66 | } 67 | 68 | private boolean isServiceRunning(Class serviceClass, Context ctx) { 69 | ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); 70 | for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { 71 | if (serviceClass.getName().equals(service.service.getClassName())) { 72 | if (DEBUG) Log.i(TAG, "Check service already running"); 73 | return true; 74 | } 75 | } 76 | if (DEBUG) Log.i(TAG, "Check service not running"); 77 | return false; 78 | } 79 | 80 | private boolean isInstalled(Context ctx, final String packageName) { 81 | final PackageManager pm = ctx.getPackageManager(); 82 | String mVersion; 83 | try { 84 | mVersion = pm.getPackageInfo(packageName, 0).versionName; 85 | if (mVersion.equals(null)) { 86 | return false; 87 | } 88 | } catch (NameNotFoundException e) { 89 | if (DEBUG) Log.e(TAG, "Package " + packageName + " NameNotFoundException" + e); 90 | return false; 91 | } 92 | return true; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/AntiPiracyNotifyService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.antipiracy.support; 18 | 19 | import android.app.Service; 20 | import android.content.Context; 21 | import android.content.Intent; 22 | import android.content.pm.PackageManager; 23 | import android.content.pm.PackageManager.NameNotFoundException; 24 | import android.net.Uri; 25 | import android.os.Handler; 26 | import android.os.IBinder; 27 | import android.os.Message; 28 | import android.util.Log; 29 | 30 | import java.lang.reflect.InvocationTargetException; 31 | import java.lang.reflect.Method; 32 | import java.util.ArrayList; 33 | import java.util.List; 34 | 35 | import org.antipiracy.support.utils.AntiPiracyUtils; 36 | import org.antipiracy.support.utils.AntiPiracyUtils.PackageDeleteObserver; 37 | 38 | import static org.antipiracy.support.utils.AntiPiracyConstants.*; 39 | 40 | /** This service blocks the install of known piracy/malware apps. Please report new piracy 41 | * apps to ROM developers deploying this code. 42 | * @author github.com/AlmightyMegadeth00 - activethrasher00@gmail.com 43 | */ 44 | public class AntiPiracyNotifyService extends Service { 45 | static final String TAG = "ANTI-PIRACY: Notify service"; 46 | 47 | // Notify service handler 48 | EventHandler mHandler = new EventHandler(); 49 | static final int MSG_UNINSTALL = 100; 50 | static final int MSG_FINISH = 101; 51 | 52 | AntiPiracyUtils.PackageDeleteObserver mObserverDelete; 53 | Method mUninstallMethod; 54 | PackageManager mPm; 55 | 56 | volatile boolean _init = false; 57 | 58 | List mInstalledList = new ArrayList(); 59 | 60 | @Override 61 | public int onStartCommand(Intent intent, int flags, int startId) { 62 | mPm = this.getPackageManager(); 63 | mObserverDelete = AntiPiracyUtils.getPackageDeleteObserver(); 64 | 65 | try { 66 | mUninstallMethod = AntiPiracyUtils.getUninstallTypes(mPm); 67 | } catch (NoSuchMethodException WTF) { 68 | Log.e(TAG, "NoSuchMethodException" + WTF); 69 | // Unfortunately, we're finished without this 70 | shutdown(); 71 | } 72 | 73 | String[] packageNames = PACKAGES; 74 | for (String app : packageNames) { 75 | if (isInstalled(app)) { 76 | mInstalledList.add(app); 77 | } 78 | } 79 | 80 | if (!_init) { 81 | mHandler.sendEmptyMessage(MSG_UNINSTALL); 82 | _init = true; 83 | } 84 | return Service.START_REDELIVER_INTENT; 85 | } 86 | 87 | @Override 88 | public IBinder onBind(Intent intent) { 89 | return null; 90 | } 91 | 92 | @Override 93 | public void onDestroy() { 94 | super.onDestroy(); 95 | if (mHandler != null) { 96 | mHandler.sendEmptyMessage(MSG_FINISH); 97 | mHandler = null; 98 | } 99 | this.stopSelf(); 100 | } 101 | 102 | void shutdown() { 103 | if (mHandler != null) { 104 | mHandler.sendEmptyMessage(MSG_FINISH); 105 | mHandler = null; 106 | } 107 | this.stopSelf(); 108 | } 109 | 110 | private boolean isInstalled(final String packageName) { 111 | String mVersion; 112 | try { 113 | mVersion = mPm.getPackageInfo(packageName, 0).versionName; 114 | if (mVersion.equals(null)) { 115 | return false; 116 | } 117 | } catch (NameNotFoundException e) { 118 | if (DEBUG) Log.e(TAG, "Package " + packageName + " NameNotFoundException" + e); 119 | return false; 120 | } 121 | return true; 122 | } 123 | 124 | private class EventHandler extends Handler { 125 | public void handleMessage(Message m) { 126 | switch (m.what) { 127 | case MSG_UNINSTALL: 128 | // uninstall 129 | try { 130 | uninstallPackages(); 131 | } catch (IllegalAccessException WTF) { 132 | Log.e(TAG, "IllegalAccessException" + WTF); 133 | } catch (InvocationTargetException BBQ) { 134 | Log.e(TAG, "InvocationTargetException" + BBQ); 135 | } 136 | break; 137 | case MSG_FINISH: 138 | this.removeMessages(0); 139 | break; 140 | default: 141 | break; 142 | } 143 | } 144 | 145 | private synchronized void uninstallPackages() throws 146 | IllegalArgumentException, IllegalAccessException, InvocationTargetException { 147 | 148 | String[] packageNames = new String[mInstalledList.size()]; 149 | packageNames = mInstalledList.toArray(packageNames); 150 | 151 | for (String app : packageNames) { 152 | mPm.setApplicationEnabledSetting(app, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0); 153 | 154 | mUninstallMethod.invoke(mPm, new Object[] { 155 | app, mObserverDelete, 0 156 | }); 157 | 158 | // Take a pause before attempting the next package. 159 | try { 160 | Thread.sleep(500); 161 | } catch (InterruptedException WTF) { 162 | Log.e(TAG, "InterruptedException" + WTF); 163 | } 164 | } 165 | 166 | // we're finished 167 | shutdown(); 168 | } 169 | } 170 | } 171 | 172 | --------------------------------------------------------------------------------