Merge change 4245 into donut
* changes:
Add the extra data definition for append location in the VIEW request to the Browser.
diff --git a/include/utils/BackupHelpers.h b/include/utils/BackupHelpers.h
index 24b6c9e..f60f4ea 100644
--- a/include/utils/BackupHelpers.h
+++ b/include/utils/BackupHelpers.h
@@ -118,7 +118,7 @@
};
int back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD,
- char const* fileBase, char const* const* files, int fileCount);
+ char const* const* files, char const* const *keys, int fileCount);
#define TEST_BACKUP_HELPERS 1
@@ -127,6 +127,8 @@
int backup_helper_test_empty();
int backup_helper_test_four();
int backup_helper_test_files();
+int backup_helper_test_null_base();
+int backup_helper_test_missing_file();
int backup_helper_test_data_writer();
int backup_helper_test_data_reader();
#endif
diff --git a/libs/utils/BackupData.cpp b/libs/utils/BackupData.cpp
index 120f23d..8c9f875 100644
--- a/libs/utils/BackupData.cpp
+++ b/libs/utils/BackupData.cpp
@@ -327,7 +327,7 @@
}
size_t size = m_header.app.packageLen;
char* buf = packageName->lockBuffer(size);
- if (packageName == NULL) {
+ if (buf == NULL) {
packageName->unlockBuffer();
m_status = ENOMEM;
return m_status;
diff --git a/libs/utils/BackupHelpers.cpp b/libs/utils/BackupHelpers.cpp
index 7f423a8..4c3e37d 100644
--- a/libs/utils/BackupHelpers.cpp
+++ b/libs/utils/BackupHelpers.cpp
@@ -41,8 +41,8 @@
#define MAGIC0 0x70616e53 // Snap
#define MAGIC1 0x656c6946 // File
-#if 0 // TEST_BACKUP_HELPERS
-#define LOGP(x...) printf(x)
+#if 1 // TEST_BACKUP_HELPERS
+#define LOGP(f, x...) printf(f "\n", x)
#else
#define LOGP(x...) LOGD(x)
#endif
@@ -62,6 +62,12 @@
int nameLen;
};
+struct FileRec {
+ char const* file; // this object does not own this string
+ bool deleted;
+ FileState s;
+};
+
const static int ROUND_UP[4] = { 0, 3, 2, 1 };
static inline int
@@ -92,8 +98,8 @@
FileState file;
char filenameBuf[128];
- amt = read(fd, &file, sizeof(file));
- if (amt != sizeof(file)) {
+ amt = read(fd, &file, sizeof(FileState));
+ if (amt != sizeof(FileState)) {
LOGW("read_snapshot_file FileState truncated/error with read at %d bytes\n", bytesRead);
return 1;
}
@@ -128,20 +134,25 @@
}
static int
-write_snapshot_file(int fd, const KeyedVector<String8,FileState>& snapshot)
+write_snapshot_file(int fd, const KeyedVector<String8,FileRec>& snapshot)
{
+ int fileCount = 0;
int bytesWritten = sizeof(SnapshotHeader);
// preflight size
const int N = snapshot.size();
for (int i=0; i<N; i++) {
- const String8& name = snapshot.keyAt(i);
- bytesWritten += sizeof(FileState) + round_up(name.length());
+ const FileRec& g = snapshot.valueAt(i);
+ if (!g.deleted) {
+ const String8& name = snapshot.keyAt(i);
+ bytesWritten += sizeof(FileState) + round_up(name.length());
+ fileCount++;
+ }
}
LOGP("write_snapshot_file fd=%d\n", fd);
int amt;
- SnapshotHeader header = { MAGIC0, N, MAGIC1, bytesWritten };
+ SnapshotHeader header = { MAGIC0, fileCount, MAGIC1, bytesWritten };
amt = write(fd, &header, sizeof(header));
if (amt != sizeof(header)) {
@@ -149,32 +160,34 @@
return errno;
}
- for (int i=0; i<header.fileCount; i++) {
- const String8& name = snapshot.keyAt(i);
- FileState file = snapshot.valueAt(i);
- int nameLen = file.nameLen = name.length();
+ for (int i=0; i<N; i++) {
+ FileRec r = snapshot.valueAt(i);
+ if (!r.deleted) {
+ const String8& name = snapshot.keyAt(i);
+ int nameLen = r.s.nameLen = name.length();
- amt = write(fd, &file, sizeof(file));
- if (amt != sizeof(file)) {
- LOGW("write_snapshot_file error writing header %s", strerror(errno));
- return 1;
- }
-
- // filename is not NULL terminated, but it is padded
- amt = write(fd, name.string(), nameLen);
- if (amt != nameLen) {
- LOGW("write_snapshot_file error writing filename %s", strerror(errno));
- return 1;
- }
- int paddingLen = ROUND_UP[nameLen % 4];
- if (paddingLen != 0) {
- int padding = 0xabababab;
- amt = write(fd, &padding, paddingLen);
- if (amt != paddingLen) {
- LOGW("write_snapshot_file error writing %d bytes of filename padding %s",
- paddingLen, strerror(errno));
+ amt = write(fd, &r.s, sizeof(FileState));
+ if (amt != sizeof(FileState)) {
+ LOGW("write_snapshot_file error writing header %s", strerror(errno));
return 1;
}
+
+ // filename is not NULL terminated, but it is padded
+ amt = write(fd, name.string(), nameLen);
+ if (amt != nameLen) {
+ LOGW("write_snapshot_file error writing filename %s", strerror(errno));
+ return 1;
+ }
+ int paddingLen = ROUND_UP[nameLen % 4];
+ if (paddingLen != 0) {
+ int padding = 0xabababab;
+ amt = write(fd, &padding, paddingLen);
+ if (amt != paddingLen) {
+ LOGW("write_snapshot_file error writing %d bytes of filename padding %s",
+ paddingLen, strerror(errno));
+ return 1;
+ }
+ }
}
}
@@ -190,9 +203,9 @@
static int
write_update_file(BackupDataWriter* dataStream, int fd, const String8& key,
- const String8& realFilename)
+ char const* realFilename)
{
- LOGP("write_update_file %s (%s)\n", realFilename.string(), key.string());
+ LOGP("write_update_file %s (%s)\n", realFilename, key.string());
const int bufsize = 4*1024;
int err;
@@ -237,8 +250,7 @@
}
}
LOGE("write_update_file size mismatch for %s. expected=%d actual=%d."
- " You aren't doing proper locking!",
- realFilename.string(), fileSize, fileSize-bytesLeft);
+ " You aren't doing proper locking!", realFilename, fileSize, fileSize-bytesLeft);
}
free(buf);
@@ -247,10 +259,10 @@
}
static int
-write_update_file(BackupDataWriter* dataStream, const String8& key, const String8& realFilename)
+write_update_file(BackupDataWriter* dataStream, const String8& key, char const* realFilename)
{
int err;
- int fd = open(realFilename.string(), O_RDONLY);
+ int fd = open(realFilename, O_RDONLY);
if (fd == -1) {
return errno;
}
@@ -281,12 +293,11 @@
int
back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD,
- char const* fileBase, char const* const* files, int fileCount)
+ char const* const* files, char const* const* keys, int fileCount)
{
int err;
- const String8 base(fileBase);
KeyedVector<String8,FileState> oldSnapshot;
- KeyedVector<String8,FileState> newSnapshot;
+ KeyedVector<String8,FileRec> newSnapshot;
if (oldSnapshotFD != -1) {
err = read_snapshot_file(oldSnapshotFD, &oldSnapshot);
@@ -297,26 +308,29 @@
}
for (int i=0; i<fileCount; i++) {
- String8 name(files[i]);
- FileState s;
+ String8 key(keys[i]);
+ FileRec r;
+ char const* file = r.file = files[i];
struct stat st;
- String8 realFilename(base);
- realFilename.appendPath(name);
- err = stat(realFilename.string(), &st);
+ err = stat(file, &st);
if (err != 0) {
- LOGW("Error stating file %s", realFilename.string());
- continue;
+ LOGW("Error stating file %s", file);
+ r.deleted = true;
+ } else {
+ r.deleted = false;
+ r.s.modTime_sec = st.st_mtime;
+ r.s.modTime_nsec = 0; // workaround sim breakage
+ //r.s.modTime_nsec = st.st_mtime_nsec;
+ r.s.size = st.st_size;
+ // we compute the crc32 later down below, when we already have the file open.
+
+ if (newSnapshot.indexOfKey(key) >= 0) {
+ LOGP("back_up_files key already in use '%s'", key.string());
+ return -1;
+ }
}
-
- s.modTime_sec = st.st_mtime;
- s.modTime_nsec = 0; // workaround sim breakage
- //s.modTime_nsec = st.st_mtime_nsec;
- s.size = st.st_size;
-
- // we compute the crc32 later down below, when we already have the file open.
-
- newSnapshot.add(name, s);
+ newSnapshot.add(key, r);
}
int n = 0;
@@ -326,46 +340,42 @@
while (n<N && m<fileCount) {
const String8& p = oldSnapshot.keyAt(n);
const String8& q = newSnapshot.keyAt(m);
+ FileRec& g = newSnapshot.editValueAt(m);
int cmp = p.compare(q);
- if (cmp > 0) {
- // file added
- String8 realFilename(base);
- realFilename.appendPath(q);
- LOGP("file added: %s\n", realFilename.string());
- write_update_file(dataStream, q, realFilename);
- m++;
- }
- else if (cmp < 0) {
+ if (g.deleted || cmp < 0) {
// file removed
- LOGP("file removed: %s\n", p.string());
+ LOGP("file removed: %s", p.string());
+ g.deleted = true; // They didn't mention the file, but we noticed that it's gone.
dataStream->WriteEntityHeader(p, -1);
n++;
}
+ else if (cmp > 0) {
+ // file added
+ LOGP("file added: %s", g.file);
+ write_update_file(dataStream, q, g.file);
+ m++;
+ }
else {
-
// both files exist, check them
- String8 realFilename(base);
- realFilename.appendPath(q);
const FileState& f = oldSnapshot.valueAt(n);
- FileState& g = newSnapshot.editValueAt(m);
- int fd = open(realFilename.string(), O_RDONLY);
+ int fd = open(g.file, O_RDONLY);
if (fd < 0) {
// We can't open the file. Don't report it as a delete either. Let the
// server keep the old version. Maybe they'll be able to deal with it
// on restore.
- LOGP("Unable to open file %s - skipping", realFilename.string());
+ LOGP("Unable to open file %s - skipping", g.file);
} else {
- g.crc32 = compute_crc32(fd);
+ g.s.crc32 = compute_crc32(fd);
- LOGP("%s\n", q.string());
- LOGP(" new: modTime=%d,%d size=%-3d crc32=0x%08x\n",
+ LOGP("%s", q.string());
+ LOGP(" new: modTime=%d,%d size=%-3d crc32=0x%08x",
f.modTime_sec, f.modTime_nsec, f.size, f.crc32);
- LOGP(" old: modTime=%d,%d size=%-3d crc32=0x%08x\n",
- g.modTime_sec, g.modTime_nsec, g.size, g.crc32);
- if (f.modTime_sec != g.modTime_sec || f.modTime_nsec != g.modTime_nsec
- || f.size != g.size || f.crc32 != g.crc32) {
- write_update_file(dataStream, fd, p, realFilename);
+ LOGP(" old: modTime=%d,%d size=%-3d crc32=0x%08x",
+ g.s.modTime_sec, g.s.modTime_nsec, g.s.size, g.s.crc32);
+ if (f.modTime_sec != g.s.modTime_sec || f.modTime_nsec != g.s.modTime_nsec
+ || f.size != g.s.size || f.crc32 != g.s.crc32) {
+ write_update_file(dataStream, fd, p, g.file);
}
close(fd);
@@ -384,9 +394,8 @@
// these were added
while (m<fileCount) {
const String8& q = newSnapshot.keyAt(m);
- String8 realFilename(base);
- realFilename.appendPath(q);
- write_update_file(dataStream, q, realFilename);
+ FileRec& g = newSnapshot.editValueAt(m);
+ write_update_file(dataStream, q, g.file);
m++;
}
@@ -475,7 +484,7 @@
{
int err;
int fd;
- KeyedVector<String8,FileState> snapshot;
+ KeyedVector<String8,FileRec> snapshot;
const char* filename = SCRATCH_DIR "backup_helper_test_empty.snap";
system("rm -r " SCRATCH_DIR);
@@ -534,7 +543,7 @@
{
int err;
int fd;
- KeyedVector<String8,FileState> snapshot;
+ KeyedVector<String8,FileRec> snapshot;
const char* filename = SCRATCH_DIR "backup_helper_test_four.snap";
system("rm -r " SCRATCH_DIR);
@@ -549,38 +558,45 @@
String8 filenames[4];
FileState states[4];
+ FileRec r;
+ r.deleted = false;
+ r.file = NULL;
states[0].modTime_sec = 0xfedcba98;
states[0].modTime_nsec = 0xdeadbeef;
states[0].size = 0xababbcbc;
states[0].crc32 = 0x12345678;
states[0].nameLen = -12;
+ r.s = states[0];
filenames[0] = String8("bytes_of_padding");
- snapshot.add(filenames[0], states[0]);
+ snapshot.add(filenames[0], r);
states[1].modTime_sec = 0x93400031;
states[1].modTime_nsec = 0xdeadbeef;
states[1].size = 0x88557766;
states[1].crc32 = 0x22334422;
states[1].nameLen = -1;
+ r.s = states[1];
filenames[1] = String8("bytes_of_padding3");
- snapshot.add(filenames[1], states[1]);
+ snapshot.add(filenames[1], r);
states[2].modTime_sec = 0x33221144;
states[2].modTime_nsec = 0xdeadbeef;
states[2].size = 0x11223344;
states[2].crc32 = 0x01122334;
states[2].nameLen = 0;
+ r.s = states[2];
filenames[2] = String8("bytes_of_padding_2");
- snapshot.add(filenames[2], states[2]);
+ snapshot.add(filenames[2], r);
states[3].modTime_sec = 0x33221144;
states[3].modTime_nsec = 0xdeadbeef;
states[3].size = 0x11223344;
states[3].crc32 = 0x01122334;
states[3].nameLen = 0;
+ r.s = states[3];
filenames[3] = String8("bytes_of_padding__1");
- snapshot.add(filenames[3], states[3]);
+ snapshot.add(filenames[3], r);
err = write_snapshot_file(fd, snapshot);
@@ -982,6 +998,14 @@
write_text_file(SCRATCH_DIR "data/h", "h\nhh\n");
char const* files_before[] = {
+ SCRATCH_DIR "data/b",
+ SCRATCH_DIR "data/c",
+ SCRATCH_DIR "data/d",
+ SCRATCH_DIR "data/e",
+ SCRATCH_DIR "data/f"
+ };
+
+ char const* keys_before[] = {
"data/b",
"data/c",
"data/d",
@@ -1004,7 +1028,7 @@
{
BackupDataWriter dataStream(dataStreamFD);
- err = back_up_files(-1, &dataStream, newSnapshotFD, SCRATCH_DIR, files_before, 5);
+ err = back_up_files(-1, &dataStream, newSnapshotFD, files_before, keys_before, 5);
if (err != 0) {
return err;
}
@@ -1035,6 +1059,15 @@
unlink(SCRATCH_DIR "data/f");
char const* files_after[] = {
+ SCRATCH_DIR "data/a", // added
+ SCRATCH_DIR "data/b", // same
+ SCRATCH_DIR "data/c", // different mod time
+ SCRATCH_DIR "data/d", // different size (same mod time)
+ SCRATCH_DIR "data/e", // different contents (same mod time, same size)
+ SCRATCH_DIR "data/g" // added
+ };
+
+ char const* keys_after[] = {
"data/a", // added
"data/b", // same
"data/c", // different mod time
@@ -1064,8 +1097,7 @@
{
BackupDataWriter dataStream(dataStreamFD);
- err = back_up_files(oldSnapshotFD, &dataStream, newSnapshotFD, SCRATCH_DIR,
- files_after, 6);
+ err = back_up_files(oldSnapshotFD, &dataStream, newSnapshotFD, files_after, keys_after, 6);
if (err != 0) {
return err;
}
@@ -1078,6 +1110,109 @@
return 0;
}
+int
+backup_helper_test_null_base()
+{
+ int err;
+ int oldSnapshotFD;
+ int dataStreamFD;
+ int newSnapshotFD;
+
+ system("rm -r " SCRATCH_DIR);
+ mkdir(SCRATCH_DIR, 0777);
+ mkdir(SCRATCH_DIR "data", 0777);
+
+ write_text_file(SCRATCH_DIR "data/a", "a\naa\n");
+
+ char const* files[] = {
+ SCRATCH_DIR "data/a",
+ };
+
+ char const* keys[] = {
+ "a",
+ };
+
+ dataStreamFD = creat(SCRATCH_DIR "null_base.data", 0666);
+ if (dataStreamFD == -1) {
+ fprintf(stderr, "error creating: %s\n", strerror(errno));
+ return errno;
+ }
+
+ newSnapshotFD = creat(SCRATCH_DIR "null_base.snap", 0666);
+ if (newSnapshotFD == -1) {
+ fprintf(stderr, "error creating: %s\n", strerror(errno));
+ return errno;
+ }
+
+ {
+ BackupDataWriter dataStream(dataStreamFD);
+
+ err = back_up_files(-1, &dataStream, newSnapshotFD, files, keys, 1);
+ if (err != 0) {
+ return err;
+ }
+ }
+
+ close(dataStreamFD);
+ close(newSnapshotFD);
+
+ return 0;
+}
+
+int
+backup_helper_test_missing_file()
+{
+ int err;
+ int oldSnapshotFD;
+ int dataStreamFD;
+ int newSnapshotFD;
+
+ system("rm -r " SCRATCH_DIR);
+ mkdir(SCRATCH_DIR, 0777);
+ mkdir(SCRATCH_DIR "data", 0777);
+
+ write_text_file(SCRATCH_DIR "data/b", "b\nbb\n");
+
+ char const* files[] = {
+ SCRATCH_DIR "data/a",
+ SCRATCH_DIR "data/b",
+ SCRATCH_DIR "data/c",
+ };
+
+ char const* keys[] = {
+ "a",
+ "b",
+ "c",
+ };
+
+ dataStreamFD = creat(SCRATCH_DIR "null_base.data", 0666);
+ if (dataStreamFD == -1) {
+ fprintf(stderr, "error creating: %s\n", strerror(errno));
+ return errno;
+ }
+
+ newSnapshotFD = creat(SCRATCH_DIR "null_base.snap", 0666);
+ if (newSnapshotFD == -1) {
+ fprintf(stderr, "error creating: %s\n", strerror(errno));
+ return errno;
+ }
+
+ {
+ BackupDataWriter dataStream(dataStreamFD);
+
+ err = back_up_files(-1, &dataStream, newSnapshotFD, files, keys, 1);
+ if (err != 0) {
+ return err;
+ }
+ }
+
+ close(dataStreamFD);
+ close(newSnapshotFD);
+
+ return 0;
+}
+
+
#endif // TEST_BACKUP_HELPERS
}
diff --git a/vpn/java/android/net/vpn/L2tpIpsecProfile.java b/vpn/java/android/net/vpn/L2tpIpsecProfile.java
index a7e53d1..181619d 100644
--- a/vpn/java/android/net/vpn/L2tpIpsecProfile.java
+++ b/vpn/java/android/net/vpn/L2tpIpsecProfile.java
@@ -22,7 +22,9 @@
* The profile for L2TP-over-IPSec type of VPN.
* {@hide}
*/
-public class L2tpIpsecProfile extends SingleServerProfile {
+public class L2tpIpsecProfile extends VpnProfile {
+ private static final long serialVersionUID = 1L;
+
private String mUserCertificate;
private String mCaCertificate;
private String mUserkey;
diff --git a/vpn/java/android/net/vpn/L2tpProfile.java b/vpn/java/android/net/vpn/L2tpProfile.java
index ca4ef75..59d4981 100644
--- a/vpn/java/android/net/vpn/L2tpProfile.java
+++ b/vpn/java/android/net/vpn/L2tpProfile.java
@@ -20,7 +20,9 @@
* The profile for L2TP type of VPN.
* {@hide}
*/
-public class L2tpProfile extends SingleServerProfile {
+public class L2tpProfile extends VpnProfile {
+ private static final long serialVersionUID = 1L;
+
@Override
public VpnType getType() {
return VpnType.L2TP;
diff --git a/vpn/java/android/net/vpn/SingleServerProfile.java b/vpn/java/android/net/vpn/SingleServerProfile.java
deleted file mode 100644
index 59b5a7b..0000000
--- a/vpn/java/android/net/vpn/SingleServerProfile.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2007, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.net.vpn;
-
-import android.os.Parcel;
-
-/**
- * The profile for single-server type of VPN.
- * {@hide}
- */
-public abstract class SingleServerProfile extends VpnProfile {
- private String mServerName;
-
- public void setServerName(String name) {
- mServerName = name;
- }
-
- public String getServerName() {
- return mServerName;
- }
-
- @Override
- protected void readFromParcel(Parcel in) {
- super.readFromParcel(in);
- mServerName = in.readString();
- }
-
- @Override
- public void writeToParcel(Parcel parcel, int flags) {
- super.writeToParcel(parcel, flags);
- parcel.writeString(mServerName);
- }
-}
diff --git a/vpn/java/android/net/vpn/VpnManager.java b/vpn/java/android/net/vpn/VpnManager.java
index 6c6e52a..98795bd 100644
--- a/vpn/java/android/net/vpn/VpnManager.java
+++ b/vpn/java/android/net/vpn/VpnManager.java
@@ -48,19 +48,8 @@
private static final String PACKAGE_PREFIX =
VpnManager.class.getPackage().getName() + ".";
- /** Action to start the activity of installing a new profile. */
- public static final String ACTION_VPN_INSTALL_PROFILE =
- PACKAGE_PREFIX + "INSTALL_PROFILE";
- /**
- * Key to the installation path in the intent of installing a new profile.
- */
- public static final String KEY_INSTALLATION_PATH = "install_path";
- public static final String DEFAULT_INSTALLATION_PATH =
- "/data/local/tmp/vpn";
-
- // Action to start VPN installation monitor service
- private static final String SERVICE_VPN_INSTALL_MONITOR =
- PACKAGE_PREFIX + "INSTALLATION_MONITOR";
+ // Action to start VPN service
+ private static final String ACTION_VPN_SERVICE = PACKAGE_PREFIX + "SERVICE";
// Action to start VPN settings
private static final String ACTION_VPN_SETTINGS = PACKAGE_PREFIX + "SETTINGS";
@@ -112,53 +101,29 @@
}
}
- private String getServiceActionName(VpnType type) {
- return PACKAGE_PREFIX + type.getServiceName();
+ /**
+ * Starts the VPN service to establish VPN connection.
+ */
+ public void startVpnService() {
+ mContext.startService(new Intent(ACTION_VPN_SERVICE));
}
/**
- * Starts the VPN service of the specified type.
+ * Stops the VPN service.
*/
- public boolean startService(VpnType type) {
- String serviceAction = getServiceActionName(type);
- if (serviceAction != null) {
- Log.i(TAG, "start service: " + serviceAction);
- mContext.startService(new Intent(serviceAction));
- return true;
- } else {
- Log.w(TAG, "unknown vpn type to start service for: " + type);
- return false;
- }
+ public void stopVpnService() {
+ mContext.stopService(new Intent(ACTION_VPN_SERVICE));
}
/**
- * Stops the VPN service of the specified type.
+ * Binds the specified ServiceConnection with the VPN service.
*/
- public void stopService(VpnType type) {
- String serviceAction = getServiceActionName(type);
- if (serviceAction != null) {
- Log.i(TAG, "stop service for: " + type);
- mContext.stopService(new Intent(serviceAction));
- } else {
- Log.w(TAG, "unknown vpn type to stop service for: " + type);
- }
- }
-
- /**
- * Binds the specified ServiceConnection with the VPN service of the
- * specified type.
- */
- public boolean bindService(VpnType type, ServiceConnection c) {
- String serviceAction = getServiceActionName(type);
- if (serviceAction == null) {
- Log.w(TAG, "unknown vpn type to bind service for: " + type);
- return false;
- }
- if (!mContext.bindService(new Intent(serviceAction), c, 0)) {
- Log.w(TAG, "failed to connect to service: " + type);
+ public boolean bindVpnService(ServiceConnection c) {
+ if (!mContext.bindService(new Intent(ACTION_VPN_SERVICE), c, 0)) {
+ Log.w(TAG, "failed to connect to VPN service");
return false;
} else {
- Log.v(TAG, "succeeded to connect to service: " + type);
+ Log.d(TAG, "succeeded to connect to VPN service");
return true;
}
}
@@ -181,21 +146,6 @@
mContext.unregisterReceiver(r);
}
- /**
- * Starts the installation monitor service.
- * The service monitors the default installtion path (under /data/local/tmp)
- * and automatically starts the activity to create a new profile when new
- * configuration files appear in that path.
- */
- public void startInstallationMonitorService() {
- mContext.startService(new Intent(SERVICE_VPN_INSTALL_MONITOR));
- }
-
- /** Stops the installation monitor service. */
- public void stopInstallationMonitorService() {
- mContext.stopService(new Intent(SERVICE_VPN_INSTALL_MONITOR));
- }
-
/** Starts the VPN settings activity. */
public void startSettingsActivity() {
Intent intent = new Intent(ACTION_VPN_SETTINGS);
@@ -203,14 +153,10 @@
mContext.startActivity(intent);
}
- /**
- * Starts the activity to install a customized profile.
- * @param installPath the path where all the configuration files are located
- */
- public void startInstallProfileActivity(String installPath) {
- Intent intent = new Intent(ACTION_VPN_INSTALL_PROFILE);
- intent.putExtra(KEY_INSTALLATION_PATH, installPath);
+ /** Creates an intent to start the VPN settings activity. */
+ public Intent createSettingsActivityIntent() {
+ Intent intent = new Intent(ACTION_VPN_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- mContext.startActivity(intent);
+ return intent;
}
}
diff --git a/vpn/java/android/net/vpn/VpnProfile.java b/vpn/java/android/net/vpn/VpnProfile.java
index 7cf2608..9e24da4 100644
--- a/vpn/java/android/net/vpn/VpnProfile.java
+++ b/vpn/java/android/net/vpn/VpnProfile.java
@@ -27,11 +27,14 @@
* A VPN profile.
* {@hide}
*/
-public abstract class VpnProfile implements Parcelable {
+public abstract class VpnProfile implements Parcelable, Serializable {
+ private static final long serialVersionUID = 1L;
private String mName; // unique display name
private String mId; // unique identifier
+ private String mServerName; // VPN server name
private String mDomainSuffices; // space separated list
private String mRouteList; // space separated list
+ private String mSavedUsername;
private boolean mIsCustomized;
private transient VpnState mState = VpnState.IDLE;
@@ -57,6 +60,17 @@
}
/**
+ * Sets the name of the VPN server. Used for DNS lookup.
+ */
+ public void setServerName(String name) {
+ mServerName = name;
+ }
+
+ public String getServerName() {
+ return mServerName;
+ }
+
+ /**
* Sets the domain suffices for DNS resolution.
*
* @param entries a comma-separated list of domain suffices
@@ -83,6 +97,14 @@
return mRouteList;
}
+ public void setSavedUsername(String name) {
+ mSavedUsername = name;
+ }
+
+ public String getSavedUsername() {
+ return mSavedUsername;
+ }
+
public void setState(VpnState state) {
mState = state;
}
@@ -115,8 +137,10 @@
protected void readFromParcel(Parcel in) {
mName = in.readString();
mId = in.readString();
+ mServerName = in.readString();
mDomainSuffices = in.readString();
mRouteList = in.readString();
+ mSavedUsername = in.readString();
}
public static final Parcelable.Creator<VpnProfile> CREATOR =
@@ -141,8 +165,10 @@
parcel.writeInt(mIsCustomized ? 1 : 0);
parcel.writeString(mName);
parcel.writeString(mId);
+ parcel.writeString(mServerName);
parcel.writeString(mDomainSuffices);
parcel.writeString(mRouteList);
+ parcel.writeString(mSavedUsername);
}
public int describeContents() {
diff --git a/vpn/java/android/net/vpn/VpnState.java b/vpn/java/android/net/vpn/VpnState.java
index 78117e0..977d938 100644
--- a/vpn/java/android/net/vpn/VpnState.java
+++ b/vpn/java/android/net/vpn/VpnState.java
@@ -24,8 +24,10 @@
* {@link CONNECTED} if successful; back to {@link IDLE} if failed.
* When the connection is about to be torn down, it goes to
* {@link DISCONNECTING} and then {@link IDLE}.
+ * {@link CANCELLED} is a state when a VPN connection attempt is aborted, and
+ * is in transition to {@link IDLE}.
* {@hide}
*/
public enum VpnState {
- CONNECTING, DISCONNECTING, CONNECTED, IDLE
+ CONNECTING, DISCONNECTING, CANCELLED, CONNECTED, IDLE
}
diff --git a/vpn/java/android/net/vpn/VpnType.java b/vpn/java/android/net/vpn/VpnType.java
index dcf2078..91b0ea2 100644
--- a/vpn/java/android/net/vpn/VpnType.java
+++ b/vpn/java/android/net/vpn/VpnType.java
@@ -39,8 +39,4 @@
public Class<? extends VpnProfile> getProfileClass() {
return mClass;
}
-
- public String getServiceName() {
- return this.toString();
- }
}