5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UiAutomatorを使用しての多段swipeの実現

Last updated at Posted at 2014-05-10

目的

  • Pattern LockをAndroid Debug Bridge上から解除する
  • Pattern Lockってこんなやつね → Google画像検索

問題点

  • Android Debug Bridge(adb)にはswipeの機能が一応組み込まれているのだが,2点しか選択できないため複雑なswipe操作ができない.
adb -s <Device ID> shell input swipe x1 y1 x2 y2 

解決案

実装

  • UiAutomatorのプロジェクトの作り方などは他に譲るとして.
UiAutomator.java
public void swipe(){
    Bundle args = this.getParams();
    String x_str = args.getString("x");
    String y_str = args.getString("y");
    StringTokenizer x = new StringTokenizer(x_str, ",");
    StringTokenizer y = new StringTokenizer(y_str, ",");
    assertTrue(x.countTokens() == y.countTokens());
    Point[] point = new Point[x.countTokens()];
    int i = 0;
    while(x.hasMoreTokens()){
        point[i] = new Point(
            Integer.parseInt(x.nextToken()), Integer.parseInt(y.nextToken()));
        i++;
    }
    getUiDevice().swipe(point, 10);
}
  • 多段Swipeを一度の動作で行うため,今回はx座標,y座標をStringとして投げている.投げる値の例は”100,200,300”みたいな感じ.
  • その値をStringTokenizerで切り出し,配列作ってぶち込んでUiDeviceクラスのswipeメソッドに投げている.

実行

  • 実行については,まずUiAutomatorのプロジェクトで作成したjarファイルを対象のAndroid端末にpushします
adb -s <Device ID> shell push <Project名>.jar /data/local/tmp
  • その後,テストをmethod単位で走らせます.
adb -s <Device ID> shell uiautomator runtest <Project名>.jar -c <Package名>.<Class名>#swipe -e "x" "100,200,300" -e "y" "400,500,400"

結論

  • 最近Pythonばかり触ってたから,Javaの記法忘れてた.
5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?