Skip to content

Commit

Permalink
Testing & Library, Gitlab CI
Browse files Browse the repository at this point in the history
  • Loading branch information
romellfudi committed Oct 4, 2018
1 parent 910f381 commit d4632de
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,6 +1,6 @@
*.iml
.gradle
/local.properties
#/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
Expand Down
35 changes: 35 additions & 0 deletions .gitlab-ci.yml
@@ -0,0 +1,35 @@
# This file is a template, and might need editing before it works on your project.
# Read more about this script on this blog post https://about.gitlab.com/2016/11/30/setting-up-gitlab-ci-for-android-projects/, by Greyson Parrelli
image: openjdk:8-jdk

variables:
ANDROID_COMPILE_SDK: "26"
ANDROID_BUILD_TOOLS: "26.0.2"
ANDROID_SDK_TOOLS: "24.4.1"

before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r${ANDROID_SDK_TOOLS}-linux.tgz
- tar --extract --gzip --file=android-sdk.tgz
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
# - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
# - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
# - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew

stages:
- build_test

build_test:
stage: build_test
script:
- ./gradlew assembleDebug testDebugUnitTest -p ussd-library
artifacts:
paths:
- ussd-library/build/outputs/
- ussd-library/build/reports/
10 changes: 10 additions & 0 deletions local.properties
@@ -0,0 +1,10 @@
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Wed Aug 22 05:19:06 PET 2018
8 changes: 7 additions & 1 deletion ussd-library/build.gradle
Expand Up @@ -41,11 +41,17 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions{
unitTests.returnDefaultValues = true
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.+'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-all:1.10.19'
testImplementation 'org.powermock:powermock-module-junit4:1.6.2'
testImplementation 'org.powermock:powermock-api-mockito:1.6.2'
}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
Expand Down
Expand Up @@ -19,10 +19,10 @@
/**
*
* @author Romell Dominguez
* @version 1.1.b 27/09/2018
* @version 1.1.c 27/09/2018
* @since 1.0.a
*/
public class USSDController {
public class USSDController implements USSDInterface{

protected static USSDController instance;

Expand All @@ -38,6 +38,8 @@ public class USSDController {

protected static final String KEY_ERROR = "KEY_ERROR";

private USSDInterface ussdInterface;

/**
* The Sinfleton building method
* @param activity An activity that could call
Expand All @@ -50,6 +52,7 @@ public static USSDController getInstance(Activity activity) {
}

private USSDController(Activity activity) {
ussdInterface = this;
context = activity;
}

Expand Down Expand Up @@ -83,9 +86,14 @@ public void callUSSDInvoke(String ussdPhoneNumber, HashMap<String,HashSet<String
}
}

@Override
public void sendData(String text) {
USSDService.send(text);
}

public void send(String text, CallbackMessage callbackMessage){
this.callbackMessage = callbackMessage;
USSDService.send(text);
ussdInterface.sendData(text);
}

public static boolean verifyAccesibilityAccess(Activity act) {
Expand Down
@@ -0,0 +1,11 @@
package com.romellfudi.ussdlibrary;

/**
* @version 1.1.c
* @autor Romell Dom铆nguez
* @date 10/4/18
*/

public interface USSDInterface {
void sendData(String text);
}
Expand Up @@ -13,7 +13,7 @@
* AccessibilityService for ussd windows on Android mobile Telcom
*
* @author Romell Dominguez
* @version 1.1.b 27/09/2018
* @version 1.1.c 27/09/2018
* @since 1.0.a
*/
public class USSDService extends AccessibilityService {
Expand All @@ -38,14 +38,14 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
event.getEventTime(), event.getText()));


if (problemView(event) || LoginView(event)) {
// deal down
clickOnButton(event, 1);
USSDController.instance.callbackInvoke.over(event.getText().get(0).toString());
} else if (LoginView(event) && notInputText(event)) {
if (LoginView(event) && notInputText(event)) {
// first view or logView, do nothing, pass / FIRST MESSAGE
clickOnButton(event, 0);
USSDController.instance.callbackInvoke.over(event.getText().get(0).toString());
}else if (problemView(event) || LoginView(event)) {
// deal down
clickOnButton(event, 1);
USSDController.instance.callbackInvoke.over(event.getText().get(0).toString());
}else if (isUSSDWidget(event)) {
// ready for work
String response = event.getText().get(0).toString();
Expand Down Expand Up @@ -87,17 +87,19 @@ public static void send(String text) {
private static void setTextIntoField(AccessibilityEvent event, String data) {
USSDController ussdController = USSDController.instance;
Bundle arguments = new Bundle();
arguments.putCharSequence(
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, data);
for (int i = 0; i < event.getSource().getChildCount(); i++) {
AccessibilityNodeInfo node = event.getSource().getChild(i);
Log.d(TAG, i + ":" + node.getClassName());
if (node != null && node.getClassName().equals("android.widget.EditText")
&& !node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)) {
((ClipboardManager) ussdController.context
.getSystemService(Context.CLIPBOARD_SERVICE))
.setPrimaryClip(ClipData.newPlainText("text", data));
node.performAction(AccessibilityNodeInfo.ACTION_PASTE);
if (arguments!=null) {
arguments.putCharSequence(
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, data);
for (int i = 0; i < event.getSource().getChildCount(); i++) {
AccessibilityNodeInfo node = event.getSource().getChild(i);
Log.d(TAG, i + ":" + node.getClassName());
if (node != null && node.getClassName().equals("android.widget.EditText")
&& !node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)) {
((ClipboardManager) ussdController.context
.getSystemService(Context.CLIPBOARD_SERVICE))
.setPrimaryClip(ClipData.newPlainText("text", data));
node.performAction(AccessibilityNodeInfo.ACTION_PASTE);
}
}
}
}
Expand All @@ -107,13 +109,15 @@ private static void setTextIntoField(AccessibilityEvent event, String data) {
* @param event AccessibilityEvent
* @return boolean has or not input text
*/
private static boolean notInputText(AccessibilityEvent event) {
protected static boolean notInputText(AccessibilityEvent event) {
boolean flag = true;
for (int i = 0; i < event.getSource().getChildCount(); i++) {
AccessibilityNodeInfo node = event.getSource().getChild(i);
if (node != null && node.getClassName().equals("android.widget.EditText"))
flag = false;
}
AccessibilityNodeInfo nodeInfo = event.getSource();
if (nodeInfo!=null)
for (int i = 0; i < nodeInfo.getChildCount(); i++) {
AccessibilityNodeInfo node = event.getSource().getChild(i);
if (node != null && node.getClassName().equals("android.widget.EditText"))
flag = false;
}
return flag;
}

Expand Down Expand Up @@ -154,7 +158,7 @@ protected boolean problemView(AccessibilityEvent event) {
* @param event AccessibilityEvent
* @param index button's index
*/
private static void clickOnButton(AccessibilityEvent event,int index) {
protected static void clickOnButton(AccessibilityEvent event,int index) {
if (event.getSource() != null) {
int count = -1;
for (int i = 0; i < event.getSource().getChildCount(); i++) {
Expand Down

0 comments on commit d4632de

Please sign in to comment.