isundil 4 năm trước cách đây
mục cha
commit
f7c45d18e5

+ 3 - 3
.idea/gradle.xml

@@ -1,11 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
+  <component name="GradleMigrationSettings" migrationVersion="1" />
   <component name="GradleSettings">
     <option name="linkedExternalProjectsSettings">
       <GradleProjectSettings>
-        <compositeConfiguration>
-          <compositeBuild compositeDefinitionSource="SCRIPT" />
-        </compositeConfiguration>
+        <option name="testRunner" value="PLATFORM" />
         <option name="distributionType" value="DEFAULT_WRAPPED" />
         <option name="externalProjectPath" value="$PROJECT_DIR$" />
         <option name="modules">
@@ -16,6 +15,7 @@
           </set>
         </option>
         <option name="resolveModulePerSourceSet" value="false" />
+        <option name="useQualifiedModuleNames" value="true" />
       </GradleProjectSettings>
     </option>
   </component>

+ 17 - 3
.idea/misc.xml

@@ -5,7 +5,7 @@
     <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
     <option name="myNullables">
       <value>
-        <list size="7">
+        <list size="14">
           <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
           <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
           <item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
@@ -13,23 +13,37 @@
           <item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
           <item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
           <item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
+          <item index="7" class="java.lang.String" itemvalue="com.android.annotations.Nullable" />
+          <item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
+          <item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
+          <item index="10" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
+          <item index="11" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" />
+          <item index="12" class="java.lang.String" itemvalue="io.reactivex.annotations.Nullable" />
+          <item index="13" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.Nullable" />
         </list>
       </value>
     </option>
     <option name="myNotNulls">
       <value>
-        <list size="6">
+        <list size="13">
           <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
           <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
           <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
           <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
           <item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
           <item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
+          <item index="6" class="java.lang.String" itemvalue="com.android.annotations.NonNull" />
+          <item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
+          <item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
+          <item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
+          <item index="10" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.NonNull" />
+          <item index="11" class="java.lang.String" itemvalue="io.reactivex.annotations.NonNull" />
+          <item index="12" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.NonNull" />
         </list>
       </value>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 5 - 2
app/build.gradle

@@ -9,16 +9,17 @@ android {
             storePassword 'android'
         }
     }
-    compileSdkVersion 28
+    compileSdkVersion 29
     defaultConfig {
         applicationId "info.knacki.pass"
         minSdkVersion 15
-        targetSdkVersion 28
+        targetSdkVersion 29
         versionCode 1
         versionName "1.0.1"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
         vectorDrawables.useSupportLibrary = true
         signingConfig signingConfigs.release
+        multiDexEnabled true
     }
     buildTypes {
         release {
@@ -49,10 +50,12 @@ dependencies {
     implementation 'com.android.support:support-v4:28.0.0'
     implementation 'com.android.support:support-vector-drawable:28.0.0'
     implementation 'com.android.support:design:28.0.0'
+    implementation 'com.android.support:multidex:1.0.3'
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'com.android.support.test:runner:1.0.2'
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
     implementation 'org.bouncycastle:bcpg-jdk15on:1.60'
     implementation 'org.bouncycastle:bcprov-jdk15on:1.60'
     implementation project(path: ':gitdroid')
+    implementation 'org.eclipse.jgit:org.eclipse.jgit:5.11.0.202103091610-r'
 }

+ 140 - 0
app/src/main/java/info/knacki/pass/jgit/JGitWrapper.java

@@ -0,0 +1,140 @@
+package info.knacki.pass.jgit;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
+import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import info.knacki.gitdroid.GitConfig;
+import info.knacki.gitdroid.GitInterface;
+import info.knacki.gitdroid.callback.OnResponseListener;
+import info.knacki.gitdroid.callback.OnStreamResponseListener;
+import info.knacki.gitdroid.entities.GitCommit;
+import info.knacki.gitdroid.entities.GitObject;
+import info.knacki.gitdroid.entities.GitRef;
+import info.knacki.gitdroid.io.NetworkUtils;
+
+public class JGitWrapper implements GitInterface {
+    private final static Logger log = Logger.getLogger(JGitWrapper.class.getName());
+    private final Git fGit;
+    private final Repository fRepository;
+    private final CredentialsProvider fCredProvider;
+    private final String DEFAULT_REMOTE = "origin";
+    private final PersonIdent fCommiter;
+    private final GitConfig fConfig;
+
+    private JGitWrapper(GitConfig config) throws IOException, URISyntaxException, GitAPIException {
+        fRepository = new InMemoryRepository(new DfsRepositoryDescription());
+        fGit = new Git(fRepository);
+        fGit.remoteAdd()
+                .setName(DEFAULT_REMOTE)
+                .setUri(new URIish(config.GetUrl()))
+                .call();
+        fCredProvider = GetCredentialProvider(config);
+        fCommiter = new PersonIdent(config.GetUsername(), config.GetUserEmail());
+        fConfig = config;
+    }
+
+    private synchronized void init(final Runnable onDone) {
+        new Thread() {
+            @Override
+            public void run() {
+                onDone.run();
+            }
+        }.start();
+    }
+
+    private static CredentialsProvider GetCredentialProvider(NetworkUtils.AuthConfig config) {
+        return new UsernamePasswordCredentialsProvider(config.GetUser(), config.GetPassword());
+    }
+
+    public static GitInterface Create(GitConfig config) {
+        try {
+            return new JGitWrapper(config);
+        }
+        catch (Throwable e) {
+            log.log(Level.SEVERE, "Cannot create Git Repository", e);
+            return null;
+        }
+    }
+
+    private void DoGetRefs(OnResponseListener<GitRef[]> callback) {
+        try {
+            Collection<Ref> branches = fGit.lsRemote()
+                    .setCredentialsProvider(fCredProvider)
+                    .setRemote(DEFAULT_REMOTE)
+                    .setHeads(true)
+                    .setTags(false)
+                    .call();
+            GitRef[] result = new GitRef[branches.size()];
+            int pos = 0;
+            for (Ref i : branches)
+                result[pos++] = new GitRef(i.getObjectId().name(), i.getName());
+            callback.OnResponse(result);
+        }
+        catch (GitAPIException e) {
+            log.log(Level.SEVERE, "Cannot list references", e);
+            callback.OnError("Cannot list references", e);
+        }
+    }
+
+    @Override
+    public void GetRefs(OnResponseListener<GitRef[]> callback) {
+        init(() -> {
+            DoGetRefs(callback);
+        });
+    }
+
+    @Override
+    public void FetchHead(OnStreamResponseListener<GitCommit> response) {
+
+    }
+
+    @Override
+    public void FetchBlob(GitObject.GitBlob blob, OnStreamResponseListener<byte[]> response) {
+
+    }
+
+    @Override
+    public void PushCommitBuilder(GitCommit.Builder commit, OnStreamResponseListener<Void> resp) {
+
+    }
+
+    @Override
+    public void CreateBranch(String branchName, OnStreamResponseListener<GitRef[]> callback) {
+        init(() -> {
+            try {
+                RevCommit emptyCommit = fGit.commit()
+                        .setMessage("Branch init")
+                        .setAuthor(fCommiter)
+                        .setCommitter(fCommiter)
+                        .setAllowEmpty(true)
+                        .call();
+                fGit.checkout()
+                        .setCreateBranch(true)
+                        .setStartPoint(emptyCommit)
+                        .setOrphan(true)
+                        .setName(branchName)
+                        .call();
+                DoGetRefs(callback);
+            }
+            catch (GitAPIException e) {
+                log.log(Level.SEVERE, "Cannot list references", e);
+                callback.OnError("Cannot list references", e);
+            }
+        });
+    }
+}

+ 9 - 0
app/src/main/java/info/knacki/pass/services/AccessibilityService.java

@@ -70,6 +70,15 @@ public class AccessibilityService extends android.accessibilityservice.Accessibi
         super.onServiceConnected();
         fInstance = this;
         fManagingEvent = false;
+
+        final AccessibilityServiceInfo serviceInfo = new AccessibilityServiceInfo();
+        serviceInfo.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED | AccessibilityEvent.TYPE_VIEW_FOCUSED;
+        serviceInfo.flags = AccessibilityServiceInfo.DEFAULT | AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            serviceInfo.flags |= AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
+        }
+        serviceInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
+        setServiceInfo(serviceInfo);
     }
 
     @Override

+ 18 - 0
app/src/main/java/info/knacki/pass/settings/SettingsManager.java

@@ -53,6 +53,8 @@ public class SettingsManager {
         static VCS factory(Context ctx, String system, String data) {
             if ("git".equals(system))
                 return new Git(ctx, data);
+            if ("Git (jGit)".equals(system))
+                return new GitJGit(ctx, data);
             return null;
         }
 
@@ -222,6 +224,22 @@ public class SettingsManager {
         }
     }
 
+    public static class GitJGit extends Git implements NetworkUtils.AuthConfig, GitConfig {
+
+        GitJGit(Context ctx, String data) {
+            super(ctx, data);
+        }
+
+        public GitJGit(Context ctx) {
+            super(ctx);
+        }
+
+        @Override
+        public String GetName() {
+            return "Git (jGit)";
+        }
+    }
+
     public final static String SHARED_PREF_FILE = "pass_prefs";
     @SuppressWarnings("SpellCheckingInspection") private static final String ENCRYPTION_PASSWORD = "encPasswd";
     private static final String FINGERPRINT_ACTIVE = "FingerprintEnabled";

+ 8 - 1
app/src/main/java/info/knacki/pass/settings/ui/SettingsActivity.java

@@ -43,6 +43,7 @@ import info.knacki.gitdroid.GitInterface;
 import info.knacki.gitdroid.GitInterfaceFactory;
 import info.knacki.gitdroid.callback.OnResponseListener;
 import info.knacki.gitdroid.entities.GitRef;
+import info.knacki.pass.jgit.JGitWrapper;
 import info.knacki.pass.R;
 import info.knacki.pass.io.FileInterfaceFactory;
 import info.knacki.pass.io.FileMigratoryUtils;
@@ -307,6 +308,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
                         case 0:
                             newVcs = new SettingsManager.Git(getActivity());
                             break;
+                        case 1:
+                            newVcs = new SettingsManager.GitJGit(getActivity());
+                            break;
                         default:
                             return;
                     }
@@ -506,7 +510,10 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
             if (versioning != null) {
                 GitInterface gitInterface;
                 try {
-                    gitInterface = GitInterfaceFactory.factory(versioning);
+                    if (versioning instanceof SettingsManager.GitJGit)
+                        gitInterface = JGitWrapper.Create(versioning);
+                    else
+                        gitInterface = GitInterfaceFactory.factory(versioning);
                 }
                 catch (GitInterfaceFactory.GitInterfaceException e) {
                     Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();

+ 1 - 0
app/src/main/res/values-fr/lang.xml

@@ -47,6 +47,7 @@
     <string name="pref_vcs_list_title">Outil de gestion de version</string>
     <array name="pref_vcs_list_keys">
         <item>GIT</item>
+        <item>GIT (via jGit)</item>
     </array>
     <array name="fDifficulty">
         <item>Code PIN</item>

+ 1 - 0
app/src/main/res/values/lang.xml

@@ -47,6 +47,7 @@
     <string name="pref_header_GPG">GPG settings</string>
     <array name="pref_vcs_list_keys">
         <item>GIT</item>
+        <item>GIT (via jGit)</item>
     </array>
     <array name="fDifficulty">
         <item>Number PIN</item>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1,6 +1,7 @@
 <resources>
     <string-array name="pref_vcs_list_values">
         <item>0</item>
+        <item>1</item>
     </string-array>
     <string name="id_softSettings" translatable="false">id_softSettings</string>
     <string name="id_enc_type" translatable="false">id_enc_type</string>

+ 1 - 1
build.gradle

@@ -7,7 +7,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.3.0'
+        classpath 'com.android.tools.build:gradle:4.1.3'
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
     }

+ 2 - 2
gradle/wrapper/gradle-wrapper.properties

@@ -1,6 +1,6 @@
-#Fri Feb 01 07:36:06 CET 2019
+#Mon Mar 22 22:14:01 CET 2021
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip