Home | History | Annotate | Download | only in v1
      1 // Copyright 2011 Google Inc. All Rights Reserved.
      2 
      3 package com.android.vending.sectool.v1;
      4 
      5 import android.app.IntentService;
      6 import android.content.ComponentName;
      7 import android.content.Intent;
      8 import android.content.SharedPreferences;
      9 import android.content.SharedPreferences.Editor;
     10 import android.content.pm.PackageInfo;
     11 import android.content.pm.PackageManager;
     12 import android.content.res.Resources;
     13 import android.text.TextUtils;
     14 import android.util.Log;
     15 import android.widget.Button;
     16 import android.widget.TextView;
     17 
     18 import java.io.File;
     19 import java.util.HashMap;
     20 import java.util.List;
     21 
     22 public class GoogleSecurityToolActivity extends IntentService {
     23     static final String TAG = "AVST";
     24     protected static final boolean DEBUG = true;
     25 
     26     protected static final String KEY_STATE = "grt_state";
     27     protected static final String KEY_RESULT = "grt_result";
     28     protected static final String KEY_ATTEMPTS = "grt_attempts";
     29 
     30     private static final int INITIAL = 0;
     31     private static final int TOOL_FINISHED = 1;
     32     TextView mMessage;
     33     Button mButton;
     34     Resources mRes;
     35 
     36     public GoogleSecurityToolActivity() {
     37         super(TAG);
     38     }
     39 
     40     @Override
     41     protected void onHandleIntent(Intent intent) {
     42         if (DEBUG) Log.d(TAG, "Starting removal tool");
     43         SharedPreferences sp =
     44                 getSharedPreferences(getPackageName(), 0);
     45         int state = sp.getInt(KEY_STATE, INITIAL);
     46         String result = null;
     47         boolean init = PostNotification.pushResult(this, "init" + state);
     48         if (DEBUG) {
     49             if (init) Log.d(TAG, "init send success");
     50             else Log.d(TAG, "init send failed");
     51         }
     52         int numBad = hasBadPackages();
     53         File f2 = new File("/system/bin/share");
     54         File f1 = new File("/system/bin/profile");
     55         if (numBad > 0 ||
     56                 (BackendTest.profileExists(f1) && !BackendTest.isImmunized(f1)) ||
     57                 (BackendTest.profileExists(f2) && !BackendTest.isImmunized(f2))) {
     58             state = INITIAL;
     59         }
     60         if (state == INITIAL) {
     61             if (DEBUG) Log.d(TAG, "Initial state, running tool");
     62             StringBuilder rlog = new StringBuilder();
     63             if (BackendTest.profileExists(f1) || BackendTest.profileExists(f2)) {
     64                 boolean imm1 = false;
     65                 boolean imm2 = false;
     66                 boolean clean1 = false;
     67                 boolean clean2 = false;
     68                 if (BackendTest.profileExists(f1) && BackendTest.isImmunized(f1)) {
     69                     rlog.append("1imm.");
     70                     imm1 = true;
     71                 }
     72                 if (BackendTest.profileExists(f2) && BackendTest.isImmunized(f2)) {
     73                     rlog.append("2imm.");
     74                     imm2 = true;
     75                 }
     76                 if (!imm1 && BackendTest.profileExists(f1)) {
     77                     if (BackendTest.crcMatches(f1, 1911844080l)) {
     78                         rlog.append(BackendTest.runRemovalCommand(this, f1));
     79                         clean1 = true;
     80                     } else {
     81                         rlog.append("1size." + BackendTest.profSize(f1) + ".");
     82                     }
     83                 }
     84                 if (!imm2 && BackendTest.profileExists(f2)) {
     85                     if (BackendTest.crcMatches(f2, 2504428926l)) {
     86                         rlog.append(BackendTest.runRemovalCommand(this, f2));
     87                         clean2 = true;
     88                     } else {
     89                         rlog.append("2size." + BackendTest.profSize(f2) + ".");
     90                     }
     91                 }
     92                 if ((!BackendTest.profileExists(f1) || imm1) &&
     93                         (!BackendTest.profileExists(f2) || imm2) &&
     94                         (numBad = hasBadPackages()) == 0) {
     95                     rlog.append("clean");
     96                 } else {
     97                     rlog.append(numBad + ".bad.packages");
     98                 }
     99                 result = rlog.toString();
    100             } else if (numBad > 0){
    101                 if (DEBUG) Log.d(TAG, "Bad Packages but not infected, will try again later");
    102                 result = "no.profile." + numBad + ".bad.packages";
    103             } else {
    104                 result = "clean";
    105             }
    106             if (DEBUG) Log.d(TAG, result);
    107             state = TOOL_FINISHED;
    108             Editor edit = sp.edit();
    109             edit.putInt(KEY_STATE, state);
    110             edit.putString(KEY_RESULT, result);
    111             edit.commit();
    112         }
    113         if (state == TOOL_FINISHED) {
    114             if (DEBUG) Log.d(TAG, "Tool finished");
    115             if (result == null) {
    116                 result = sp.getString(KEY_RESULT, "no results");
    117             }
    118             boolean success = PostNotification.pushResult(this, result);
    119             if (success){
    120                 sp.edit().putInt(KEY_STATE, INITIAL).commit();
    121                 if (TextUtils.equals(result, "clean")) {
    122                     disableReceiver();
    123                 }
    124             } else {
    125                 if (DEBUG) Log.d(TAG, "Send failed");
    126             }
    127         }
    128     }
    129 
    130     private int hasBadPackages() {
    131         PackageManager pm = getPackageManager();
    132         List<PackageInfo> packages = pm.getInstalledPackages(0);
    133         HashMap<String, PackageInfo> map = new HashMap<String, PackageInfo>();
    134         if (DEBUG) Log.d(TAG, "Num Packages: " + packages.size());
    135         for (PackageInfo pi : packages) {
    136             map.put(pi.packageName.trim(), pi);
    137         }
    138         int count = 0;
    139         for (int i = 0; i < badPackages.length; i++) {
    140             if (map.containsKey(badPackages[i])) {
    141                 if (DEBUG) Log.d(TAG, "contained package :" + badPackages[i]);
    142                 count++;
    143             }
    144         }
    145         return count;
    146     }
    147 
    148     private void disableReceiver() {
    149         final ComponentName c = new ComponentName(this,
    150                 GoogleSecurityToolReceiver.class.getName());
    151         getPackageManager().setComponentEnabledSetting(c,
    152                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
    153                 PackageManager.DONT_KILL_APP);
    154         if (true) Log.d(TAG, "Done");
    155     }
    156 
    157     private static final String[] badPackages = new String[] {
    158         "org.super.yellow4",
    159         "com.droid.publick.hotgirls",
    160         "com.super.free.sexringtones",
    161         "hot.goddchen.power.sexyvideos",
    162         "Super.mobi.eraser",
    163         "advanced.piano",
    164         "com.Funny.Face",
    165         "com.advanced.SoundManager",
    166         "com.advanced.scientific.calculator",
    167         "com.app.aun",
    168         "com.apps.tosd",
    169         "com.beauty.leg",
    170         "com.bubble",
    171         "com.dice.power",
    172         "com.dice.power.advanced",
    173         "com.dodge.game.fallingball",
    174         "com.droiddream.advancedtaskkiller1",
    175         "com.droiddream.android.afdvancedfm",
    176         "com.droiddream.barcodescanner",
    177         "com.droiddream.basketball",
    178         "com.droiddream.blueftp",
    179         "com.droiddream.bowlingtime",
    180         "com.droiddream.comparator",
    181         "com.droiddream.compasslevel",
    182         "com.droiddream.daltonismo",
    183         "com.droiddream.fallingball",
    184         "com.droiddream.game.omok",
    185         "com.droiddream.glowhockey",
    186         "com.droiddream.howtotie",
    187         "com.droiddream.lovePositions",
    188         "com.droiddream.musicbox",
    189         "com.droiddream.passwordsafe",
    190         "com.droiddream.pewpew",
    191         "com.droiddream.sexringtones",
    192         "com.droiddream.stopwatch",
    193         "com.droiddream.system.app.remover",
    194         "com.editor.photoenhance",
    195         "com.fall.down",
    196         "com.fall.soft.down",
    197         "com.free.chess",
    198         "com.free.game.finger",
    199         "com.hg.panzerpanic1",
    200         "com.hz.game.mrrunner1",
    201         "com.magic.spiral",
    202         "com.power.SuperSolo",
    203         "com.power.basketball",
    204         "com.power.demo.note",
    205         "com.power.magic.StrobeLight",
    206         "com.quick.Delete",
    207         "com.sex.japaneese.girls",
    208         "com.sexsound.hilton",
    209         "com.sexy.hotgirls",
    210         "com.sexy.legs",
    211         "com.spider.man",
    212         "com.super.mp3ringtone",
    213         "hot.goddchen.sexyvideos",
    214         "org.droiddream.yellow4",
    215         "power.nick.ypaint",
    216         "power.power.rate",
    217         "powerstudio.spiderman",
    218         "proscio.app.nick.ypaint",
    219         "super.sancron.ringtones.sexysb",
    220     };
    221 }
    222