aboutsummaryrefslogtreecommitdiffstats
path: root/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/data/bytecode/WakelockActivity6.java.txt
blob: a122fa330e6969ee2bf8a56d67c7f9ef9791e4a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package test.pkg;

import com.example.test3.BuildConfig;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;;

public class WakelockActivity6 extends Activity {
    void wrongFlow1() {
        PowerManager manager = (PowerManager) getSystemService(POWER_SERVICE);
        PowerManager.WakeLock lock =
                manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Test");
        lock.acquire();
        if (getTaskId() == 50) {
            randomCall();
        } else {
            lock.release(); // Wrong
        }
    }

    void wrongFlow2(PowerManager.WakeLock lock) {
        lock.acquire();
        if (getTaskId() == 50) {
            randomCall();
        } else {
            lock.release(); // Wrong
        }
    }

    void okFlow1(WakeLock lock) {
        lock.acquire();
        try {
            randomCall();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.release(); // OK
        }
    }

    public void checkNullGuard(WakeLock lock) {
        lock.acquire();
        if (lock != null) {
            lock.release(); // OK
        }
    }

    @SuppressLint("Wakelock")
    public void checkDisabled1(PowerManager.WakeLock lock) {
        lock.acquire();
        randomCall();
        lock.release(); // Wrong, but disabled
    }

    void wrongFlow3(WakeLock lock) {
        int id = getTaskId();
        lock.acquire();
        if (id < 50) {
            System.out.println(1);
        } else {
            System.out.println(2);
        }
        lock.release(); // Wrong
    }

    static void randomCall() {
        System.out.println("test");
    }
}