Compare commits

...

4 Commits

Author SHA1 Message Date
5faa970b79 Feat: 다중 사용자 인증 시스템 구현
- EncryptedSharedPreferences를 사용한 암호화된 사용자 저장
- SHA-256 해싱으로 비밀번호 보안 강화 (username을 salt로 사용)
- 사용자 CRUD 기능 (추가/수정/삭제/조회)
- 사용자 관리 UI 추가 (UserManagementActivity)
- FTP 인증 로직을 placeholder에서 실제 검증으로 변경
- 기본 admin/admin 사용자 자동 생성
- 마지막 사용자 삭제 방지 기능

보안 기능:
- 이중 보안: 비밀번호 해싱 + EncryptedSharedPreferences
- 평문 저장 없음
- 유효성 검사 (username: 3-20자 영숫자+_, password: 최소 4자)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-02 05:52:05 +09:00
0c3b7054bd Fix: Windows에서 한글 파일명 분리 현상 해결
FTP RFC 2640 표준에 따라 파일명을 NFC 형식으로 전송하도록 변경.
- 기존 NFD 변환 코드 제거 (convertFileListToNFD, denormalizeFilename 호출)
- Windows 클라이언트: NFC로 받아 한글이 정상 표시
- Mac 클라이언트: NFC를 자동으로 NFD 변환하여 처리
- 파일 검색 시 NFD/NFC 양방향 호환성은 findFileWithNormalization()으로 유지

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-02 05:02:06 +09:00
3357fe76d4 Feat: 데이터 포트 범위 지정 기능 추가
방화벽 환경에서 특정 포트 범위만 개방하여 사용할 수 있도록 데이터 포트 범위 설정 기능 추가.
- FTPConfig에 minDataPort, maxDataPort 설정 추가 (기본값: 50000-50100)
- FTPDataConnection에서 지정된 범위 내 사용 가능한 포트 자동 할당
- MainActivity UI에 데이터 포트 범위 설정 필드 추가
- 포트 범위 유효성 검증 (최소 10개 포트, 1024-65535 범위)
- 범위 미지정 시 기존처럼 랜덤 포트 사용

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-02 04:33:53 +09:00
12f27e9f13 Fix: 앱 재시작 시 UI 상태와 서비스 상태 동기화 문제 해결
onResume()에서 실제 FTPService 실행 상태를 확인하여 UI를 동기화함으로써 화면 전환 또는 앱 재시작 시에도 올바른 버튼 상태가 표시되도록 수정.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-02 02:10:39 +09:00
15 changed files with 983 additions and 35 deletions

View File

@@ -32,6 +32,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0' implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.security:security-crypto:1.1.0-alpha06'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

View File

@@ -31,6 +31,15 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".UserManagementActivity"
android:label="Manage Users"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<service <service
android:name=".FTPService" android:name=".FTPService"
android:enabled="true" android:enabled="true"

View File

@@ -9,8 +9,12 @@ public class FTPConfig {
private static final String KEY_PORT = "ftp_port"; private static final String KEY_PORT = "ftp_port";
private static final String KEY_ROOT_DIR_URI = "root_directory_uri"; private static final String KEY_ROOT_DIR_URI = "root_directory_uri";
private static final String KEY_ROOT_DIR_PATH = "root_directory_path"; private static final String KEY_ROOT_DIR_PATH = "root_directory_path";
private static final String KEY_MIN_DATA_PORT = "min_data_port";
private static final String KEY_MAX_DATA_PORT = "max_data_port";
private static final int DEFAULT_PORT = 2121; private static final int DEFAULT_PORT = 2121;
private static final int DEFAULT_MIN_DATA_PORT = 50000;
private static final int DEFAULT_MAX_DATA_PORT = 50100;
private final SharedPreferences preferences; private final SharedPreferences preferences;
@@ -60,4 +64,27 @@ public class FTPConfig {
.putString(KEY_ROOT_DIR_PATH, rootDirPath) .putString(KEY_ROOT_DIR_PATH, rootDirPath)
.apply(); .apply();
} }
public int getMinDataPort() {
return preferences.getInt(KEY_MIN_DATA_PORT, DEFAULT_MIN_DATA_PORT);
}
public void setMinDataPort(int port) {
preferences.edit().putInt(KEY_MIN_DATA_PORT, port).apply();
}
public int getMaxDataPort() {
return preferences.getInt(KEY_MAX_DATA_PORT, DEFAULT_MAX_DATA_PORT);
}
public void setMaxDataPort(int port) {
preferences.edit().putInt(KEY_MAX_DATA_PORT, port).apply();
}
public void setDataPortRange(int minPort, int maxPort) {
preferences.edit()
.putInt(KEY_MIN_DATA_PORT, minPort)
.putInt(KEY_MAX_DATA_PORT, maxPort)
.apply();
}
} }

View File

@@ -20,14 +20,41 @@ public class FTPDataConnection {
private int passivePort; private int passivePort;
public boolean openPassiveMode(InetAddress bindAddress) { public boolean openPassiveMode(InetAddress bindAddress) {
try { return openPassiveMode(bindAddress, 0, 0);
// Use port 0 to get a random available port }
passiveSocket = new ServerSocket(0, 1, bindAddress);
passiveSocket.setSoTimeout(DATA_CONNECTION_TIMEOUT);
passivePort = passiveSocket.getLocalPort();
Log.i(TAG, "Passive mode enabled on port: " + passivePort); public boolean openPassiveMode(InetAddress bindAddress, int minPort, int maxPort) {
return true; try {
if (minPort <= 0 || maxPort <= 0 || minPort > maxPort) {
// Use port 0 to get a random available port
passiveSocket = new ServerSocket(0, 1, bindAddress);
passiveSocket.setSoTimeout(DATA_CONNECTION_TIMEOUT);
passivePort = passiveSocket.getLocalPort();
Log.i(TAG, "Passive mode enabled on random port: " + passivePort);
return true;
}
// Try to find an available port in the specified range
IOException lastException = null;
for (int port = minPort; port <= maxPort; port++) {
try {
passiveSocket = new ServerSocket(port, 1, bindAddress);
passiveSocket.setSoTimeout(DATA_CONNECTION_TIMEOUT);
passivePort = passiveSocket.getLocalPort();
Log.i(TAG, "Passive mode enabled on port: " + passivePort + " (range: " + minPort + "-" + maxPort + ")");
return true;
} catch (IOException e) {
lastException = e;
// Port is in use, try next port
}
}
// No available port found in range
Log.e(TAG, "No available port in range " + minPort + "-" + maxPort);
if (lastException != null) {
Log.e(TAG, "Last error: " + lastException.getMessage());
}
return false;
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error opening passive mode: " + e.getMessage()); Log.e(TAG, "Error opening passive mode: " + e.getMessage());
return false; return false;

View File

@@ -23,20 +23,30 @@ public class FTPServer {
private int port; private int port;
private Context context; private Context context;
private Uri rootDirectoryUri; private Uri rootDirectoryUri;
private int minDataPort = 0;
private int maxDataPort = 0;
private FTPUserManager userManager;
public FTPServer(Context context) { public FTPServer(Context context) {
this(context, DEFAULT_PORT, null); this(context, DEFAULT_PORT, null, 0, 0);
} }
public FTPServer(Context context, int port) { public FTPServer(Context context, int port) {
this(context, port, null); this(context, port, null, 0, 0);
} }
public FTPServer(Context context, int port, Uri rootDirectoryUri) { public FTPServer(Context context, int port, Uri rootDirectoryUri) {
this(context, port, rootDirectoryUri, 0, 0);
}
public FTPServer(Context context, int port, Uri rootDirectoryUri, int minDataPort, int maxDataPort) {
this.context = context; this.context = context;
this.port = port; this.port = port;
this.rootDirectoryUri = rootDirectoryUri; this.rootDirectoryUri = rootDirectoryUri;
this.minDataPort = minDataPort;
this.maxDataPort = maxDataPort;
this.executorService = Executors.newFixedThreadPool(MAX_CONNECTIONS); this.executorService = Executors.newFixedThreadPool(MAX_CONNECTIONS);
this.userManager = FTPUserManager.getInstance(context);
} }
public void start() { public void start() {
@@ -56,7 +66,7 @@ public class FTPServer {
Socket clientSocket = serverSocket.accept(); Socket clientSocket = serverSocket.accept();
Log.i(TAG, "New client connection from: " + clientSocket.getInetAddress()); Log.i(TAG, "New client connection from: " + clientSocket.getInetAddress());
FTPSession session = new FTPSession(clientSocket, context, rootDirectoryUri); FTPSession session = new FTPSession(clientSocket, context, rootDirectoryUri, minDataPort, maxDataPort, userManager);
executorService.execute(session); executorService.execute(session);
} catch (IOException e) { } catch (IOException e) {

View File

@@ -37,11 +37,13 @@ public class FTPService extends Service {
if (ACTION_START.equals(action)) { if (ACTION_START.equals(action)) {
int port = intent.getIntExtra("port", 2121); int port = intent.getIntExtra("port", 2121);
String rootDirUriString = intent.getStringExtra("rootDirUri"); String rootDirUriString = intent.getStringExtra("rootDirUri");
int minDataPort = intent.getIntExtra("minDataPort", 0);
int maxDataPort = intent.getIntExtra("maxDataPort", 0);
android.net.Uri rootDirUri = null; android.net.Uri rootDirUri = null;
if (rootDirUriString != null && !rootDirUriString.isEmpty()) { if (rootDirUriString != null && !rootDirUriString.isEmpty()) {
rootDirUri = android.net.Uri.parse(rootDirUriString); rootDirUri = android.net.Uri.parse(rootDirUriString);
} }
startFTPServer(port, rootDirUri); startFTPServer(port, rootDirUri, minDataPort, maxDataPort);
} else if (ACTION_STOP.equals(action)) { } else if (ACTION_STOP.equals(action)) {
stopFTPServer(); stopFTPServer();
} }
@@ -50,19 +52,24 @@ public class FTPService extends Service {
return START_STICKY; return START_STICKY;
} }
private void startFTPServer(int port, android.net.Uri rootDirUri) { private void startFTPServer(int port, android.net.Uri rootDirUri, int minDataPort, int maxDataPort) {
if (ftpServer != null && ftpServer.isRunning()) { if (ftpServer != null && ftpServer.isRunning()) {
Log.w(TAG, "FTP Server is already running"); Log.w(TAG, "FTP Server is already running");
return; return;
} }
ftpServer = new FTPServer(this, port, rootDirUri); ftpServer = new FTPServer(this, port, rootDirUri, minDataPort, maxDataPort);
ftpServer.start(); ftpServer.start();
Notification notification = createNotification("FTP Server is running on port " + ftpServer.getPort()); String notificationText = "FTP Server is running on port " + ftpServer.getPort();
if (minDataPort > 0 && maxDataPort > 0) {
notificationText += " (Data ports: " + minDataPort + "-" + maxDataPort + ")";
}
Notification notification = createNotification(notificationText);
startForeground(NOTIFICATION_ID, notification); startForeground(NOTIFICATION_ID, notification);
Log.i(TAG, "FTP Server started on port " + port + " with root URI: " + rootDirUri); Log.i(TAG, "FTP Server started on port " + port + " with root URI: " + rootDirUri +
", data port range: " + minDataPort + "-" + maxDataPort);
} }
private void stopFTPServer() { private void stopFTPServer() {

View File

@@ -31,15 +31,29 @@ public class FTPSession implements Runnable {
private FTPDataConnection dataConnection; private FTPDataConnection dataConnection;
private String transferType = "A"; // A = ASCII, I = Binary private String transferType = "A"; // A = ASCII, I = Binary
private boolean useUtf8 = true; // UTF-8 enabled by default for better compatibility private boolean useUtf8 = true; // UTF-8 enabled by default for better compatibility
private int minDataPort = 0;
private int maxDataPort = 0;
private FTPUserManager userManager;
public FTPSession(Socket socket, Context context) { public FTPSession(Socket socket, Context context) {
this(socket, context, null); this(socket, context, null, 0, 0, null);
} }
public FTPSession(Socket socket, Context context, Uri rootDirectoryUri) { public FTPSession(Socket socket, Context context, Uri rootDirectoryUri) {
this(socket, context, rootDirectoryUri, 0, 0, null);
}
public FTPSession(Socket socket, Context context, Uri rootDirectoryUri, int minDataPort, int maxDataPort) {
this(socket, context, rootDirectoryUri, minDataPort, maxDataPort, null);
}
public FTPSession(Socket socket, Context context, Uri rootDirectoryUri, int minDataPort, int maxDataPort, FTPUserManager userManager) {
this.controlSocket = socket; this.controlSocket = socket;
this.fileSystem = new FTPFileSystem(context, rootDirectoryUri); this.fileSystem = new FTPFileSystem(context, rootDirectoryUri);
this.dataConnection = null; this.dataConnection = null;
this.minDataPort = minDataPort;
this.maxDataPort = maxDataPort;
this.userManager = userManager;
} }
@Override @Override
@@ -153,10 +167,16 @@ public class FTPSession implements Runnable {
return; return;
} }
// Simple authentication - accept any password for now // Authenticate using FTPUserManager
// In production, implement proper authentication if (userManager != null && userManager.authenticate(username, password)) {
isAuthenticated = true; isAuthenticated = true;
sendResponse(FTPResponse.USER_LOGGED_IN, "User logged in"); sendResponse(FTPResponse.USER_LOGGED_IN, "User logged in");
Log.i(TAG, "User authenticated: " + username);
} else {
isAuthenticated = false;
sendResponse(FTPResponse.NOT_LOGGED_IN, "Authentication failed");
Log.w(TAG, "Authentication failed for user: " + username);
}
} }
private void handleQuit() throws IOException { private void handleQuit() throws IOException {
@@ -174,8 +194,6 @@ public class FTPSession implements Runnable {
return; return;
} }
String path = fileSystem.getCurrentPath(); String path = fileSystem.getCurrentPath();
// Convert path to NFD format for MacOS compatibility
path = denormalizeFilename(path);
sendResponse(FTPResponse.PATHNAME_CREATED, "\"" + path + "\" is current directory"); sendResponse(FTPResponse.PATHNAME_CREATED, "\"" + path + "\" is current directory");
} }
@@ -195,8 +213,6 @@ public class FTPSession implements Runnable {
if (fileSystem.changeDirectory(path)) { if (fileSystem.changeDirectory(path)) {
String currentPath = fileSystem.getCurrentPath(); String currentPath = fileSystem.getCurrentPath();
// Convert path to NFD format for MacOS compatibility
currentPath = denormalizeFilename(currentPath);
sendResponse(FTPResponse.REQUESTED_FILE_ACTION_OK, "Directory changed to " + currentPath); sendResponse(FTPResponse.REQUESTED_FILE_ACTION_OK, "Directory changed to " + currentPath);
} else { } else {
sendResponse(FTPResponse.FILE_UNAVAILABLE, "Failed to change directory"); sendResponse(FTPResponse.FILE_UNAVAILABLE, "Failed to change directory");
@@ -211,8 +227,6 @@ public class FTPSession implements Runnable {
if (fileSystem.changeToParentDirectory()) { if (fileSystem.changeToParentDirectory()) {
String currentPath = fileSystem.getCurrentPath(); String currentPath = fileSystem.getCurrentPath();
// Convert path to NFD format for MacOS compatibility
currentPath = denormalizeFilename(currentPath);
sendResponse(FTPResponse.REQUESTED_FILE_ACTION_OK, "Directory changed to " + currentPath); sendResponse(FTPResponse.REQUESTED_FILE_ACTION_OK, "Directory changed to " + currentPath);
} else { } else {
sendResponse(FTPResponse.FILE_UNAVAILABLE, "Already at root directory"); sendResponse(FTPResponse.FILE_UNAVAILABLE, "Already at root directory");
@@ -231,8 +245,6 @@ public class FTPSession implements Runnable {
} }
String fileList = fileSystem.formatFileList(true); String fileList = fileSystem.formatFileList(true);
// Convert filenames to NFD format for MacOS compatibility
fileList = convertFileListToNFD(fileList);
sendResponse(FTPResponse.FILE_STATUS_OK, "Opening data connection for directory list"); sendResponse(FTPResponse.FILE_STATUS_OK, "Opening data connection for directory list");
@@ -264,8 +276,6 @@ public class FTPSession implements Runnable {
} }
String fileList = fileSystem.formatFileList(false); String fileList = fileSystem.formatFileList(false);
// Convert filenames to NFD format for MacOS compatibility
fileList = convertFileListToNFD(fileList);
sendResponse(FTPResponse.FILE_STATUS_OK, "Opening data connection for name list"); sendResponse(FTPResponse.FILE_STATUS_OK, "Opening data connection for name list");
@@ -301,8 +311,6 @@ public class FTPSession implements Runnable {
if (fileSystem.makeDirectory(dirName)) { if (fileSystem.makeDirectory(dirName)) {
String newPath = fileSystem.getCurrentPath() + "/" + dirName; String newPath = fileSystem.getCurrentPath() + "/" + dirName;
// Convert path to NFD format for MacOS compatibility (NFC -> NFD for display)
newPath = denormalizeFilename(newPath);
sendResponse(FTPResponse.PATHNAME_CREATED, "\"" + newPath + "\" directory created"); sendResponse(FTPResponse.PATHNAME_CREATED, "\"" + newPath + "\" directory created");
} else { } else {
sendResponse(FTPResponse.FILE_UNAVAILABLE, "Failed to create directory"); sendResponse(FTPResponse.FILE_UNAVAILABLE, "Failed to create directory");
@@ -405,7 +413,7 @@ public class FTPSession implements Runnable {
// Get server address from control socket // Get server address from control socket
String serverAddress = controlSocket.getLocalAddress().getHostAddress(); String serverAddress = controlSocket.getLocalAddress().getHostAddress();
if (dataConnection.openPassiveMode(controlSocket.getLocalAddress())) { if (dataConnection.openPassiveMode(controlSocket.getLocalAddress(), minDataPort, maxDataPort)) {
int port = dataConnection.getPassivePort(); int port = dataConnection.getPassivePort();
// Format: h1,h2,h3,h4,p1,p2 // Format: h1,h2,h3,h4,p1,p2

View File

@@ -0,0 +1,53 @@
package be.gyu.android.server.ftp;
import org.json.JSONException;
import org.json.JSONObject;
public class FTPUser {
private String username;
private String passwordHash;
private long createdTimestamp;
public FTPUser(String username, String passwordHash) {
this.username = username;
this.passwordHash = passwordHash;
this.createdTimestamp = System.currentTimeMillis();
}
public FTPUser(String username, String passwordHash, long createdTimestamp) {
this.username = username;
this.passwordHash = passwordHash;
this.createdTimestamp = createdTimestamp;
}
public String getUsername() {
return username;
}
public String getPasswordHash() {
return passwordHash;
}
public long getCreatedTimestamp() {
return createdTimestamp;
}
public void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
public JSONObject toJson() throws JSONException {
JSONObject json = new JSONObject();
json.put("username", username);
json.put("passwordHash", passwordHash);
json.put("createdTimestamp", createdTimestamp);
return json;
}
public static FTPUser fromJson(JSONObject json) throws JSONException {
String username = json.getString("username");
String passwordHash = json.getString("passwordHash");
long createdTimestamp = json.optLong("createdTimestamp", System.currentTimeMillis());
return new FTPUser(username, passwordHash, createdTimestamp);
}
}

View File

@@ -0,0 +1,211 @@
package be.gyu.android.server.ftp;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import androidx.security.crypto.EncryptedSharedPreferences;
import androidx.security.crypto.MasterKey;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
public class FTPUserManager {
private static final String TAG = "FTPUserManager";
private static final String PREF_NAME = "ftp_users_encrypted";
private static final String KEY_USERS = "ftp_users";
private static FTPUserManager instance;
private SharedPreferences encryptedPrefs;
private FTPUserManager(Context context) {
try {
MasterKey masterKey = new MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build();
encryptedPrefs = EncryptedSharedPreferences.create(
context,
PREF_NAME,
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
);
} catch (Exception e) {
Log.e(TAG, "Failed to create encrypted preferences: " + e.getMessage());
}
}
public static synchronized FTPUserManager getInstance(Context context) {
if (instance == null) {
instance = new FTPUserManager(context.getApplicationContext());
}
return instance;
}
public synchronized boolean addUser(String username, String password) {
if (!isValidUsername(username) || !isValidPassword(password)) {
return false;
}
if (userExists(username)) {
Log.w(TAG, "User already exists: " + username);
return false;
}
List<FTPUser> users = loadUsers();
String passwordHash = hashPassword(password, username);
users.add(new FTPUser(username, passwordHash));
saveUsers(users);
Log.i(TAG, "User added: " + username);
return true;
}
public synchronized boolean updateUser(String username, String newPassword) {
if (!isValidPassword(newPassword)) {
return false;
}
List<FTPUser> users = loadUsers();
for (FTPUser user : users) {
if (user.getUsername().equals(username)) {
String newPasswordHash = hashPassword(newPassword, username);
user.setPasswordHash(newPasswordHash);
saveUsers(users);
Log.i(TAG, "User updated: " + username);
return true;
}
}
Log.w(TAG, "User not found for update: " + username);
return false;
}
public synchronized boolean deleteUser(String username) {
List<FTPUser> users = loadUsers();
// Prevent deleting the last user
if (users.size() <= 1) {
Log.w(TAG, "Cannot delete last user");
return false;
}
boolean removed = users.removeIf(user -> user.getUsername().equals(username));
if (removed) {
saveUsers(users);
Log.i(TAG, "User deleted: " + username);
}
return removed;
}
public synchronized List<FTPUser> getAllUsers() {
return new ArrayList<>(loadUsers());
}
public synchronized FTPUser getUser(String username) {
List<FTPUser> users = loadUsers();
for (FTPUser user : users) {
if (user.getUsername().equals(username)) {
return user;
}
}
return null;
}
public synchronized boolean authenticate(String username, String password) {
FTPUser user = getUser(username);
if (user == null) {
Log.w(TAG, "Authentication failed - user not found: " + username);
return false;
}
String passwordHash = hashPassword(password, username);
boolean authenticated = passwordHash.equals(user.getPasswordHash());
if (authenticated) {
Log.i(TAG, "User authenticated: " + username);
} else {
Log.w(TAG, "Authentication failed - wrong password: " + username);
}
return authenticated;
}
public boolean userExists(String username) {
return getUser(username) != null;
}
public boolean isValidUsername(String username) {
if (username == null || username.trim().isEmpty()) {
return false;
}
username = username.trim();
return username.length() >= 3 &&
username.length() <= 20 &&
username.matches("^[a-zA-Z0-9_]+$");
}
public boolean isValidPassword(String password) {
return password != null && password.length() >= 4;
}
private String hashPassword(String password, String salt) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
String saltedPassword = salt + password;
byte[] hash = digest.digest(saltedPassword.getBytes(StandardCharsets.UTF_8));
// Convert to hex string
StringBuilder hexString = new StringBuilder();
for (byte b : hash) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "SHA-256 not available: " + e.getMessage());
return "";
}
}
private List<FTPUser> loadUsers() {
List<FTPUser> users = new ArrayList<>();
String usersJson = encryptedPrefs.getString(KEY_USERS, "[]");
try {
JSONArray jsonArray = new JSONArray(usersJson);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject userJson = jsonArray.getJSONObject(i);
users.add(FTPUser.fromJson(userJson));
}
} catch (JSONException e) {
Log.e(TAG, "Error loading users: " + e.getMessage());
}
return users;
}
private void saveUsers(List<FTPUser> users) {
try {
JSONArray jsonArray = new JSONArray();
for (FTPUser user : users) {
jsonArray.put(user.toJson());
}
encryptedPrefs.edit()
.putString(KEY_USERS, jsonArray.toString())
.apply();
} catch (JSONException e) {
Log.e(TAG, "Error saving users: " + e.getMessage());
}
}
}

View File

@@ -8,6 +8,8 @@ import androidx.core.content.ContextCompat;
import androidx.documentfile.provider.DocumentFile; import androidx.documentfile.provider.DocumentFile;
import android.Manifest; import android.Manifest;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
@@ -33,6 +35,9 @@ public class MainActivity extends AppCompatActivity {
private TextView rootDirPathTextView; private TextView rootDirPathTextView;
private Button selectDirButton; private Button selectDirButton;
private Button saveSettingsButton; private Button saveSettingsButton;
private EditText minDataPortEditText;
private EditText maxDataPortEditText;
private Button manageUsersButton;
private FTPConfig config; private FTPConfig config;
private ActivityResultLauncher<Uri> directoryPickerLauncher; private ActivityResultLauncher<Uri> directoryPickerLauncher;
@@ -50,6 +55,7 @@ public class MainActivity extends AppCompatActivity {
loadSettings(); loadSettings();
setupListeners(); setupListeners();
requestPermissions(); requestPermissions();
initializeDefaultUser();
} }
private void setupDirectoryPicker() { private void setupDirectoryPicker() {
@@ -89,11 +95,16 @@ public class MainActivity extends AppCompatActivity {
rootDirPathTextView = findViewById(R.id.rootDirPathTextView); rootDirPathTextView = findViewById(R.id.rootDirPathTextView);
selectDirButton = findViewById(R.id.selectDirButton); selectDirButton = findViewById(R.id.selectDirButton);
saveSettingsButton = findViewById(R.id.saveSettingsButton); saveSettingsButton = findViewById(R.id.saveSettingsButton);
minDataPortEditText = findViewById(R.id.minDataPortEditText);
maxDataPortEditText = findViewById(R.id.maxDataPortEditText);
manageUsersButton = findViewById(R.id.manageUsersButton);
} }
private void loadSettings() { private void loadSettings() {
int port = config.getPort(); int port = config.getPort();
String rootPath = config.getRootDirectoryPath(); String rootPath = config.getRootDirectoryPath();
int minDataPort = config.getMinDataPort();
int maxDataPort = config.getMaxDataPort();
portEditText.setText(String.valueOf(port)); portEditText.setText(String.valueOf(port));
portTextView.setText("Port: " + port); portTextView.setText("Port: " + port);
@@ -103,6 +114,9 @@ public class MainActivity extends AppCompatActivity {
} else { } else {
rootDirPathTextView.setText("Not selected"); rootDirPathTextView.setText("Not selected");
} }
minDataPortEditText.setText(String.valueOf(minDataPort));
maxDataPortEditText.setText(String.valueOf(maxDataPort));
} }
private void setupListeners() { private void setupListeners() {
@@ -110,6 +124,7 @@ public class MainActivity extends AppCompatActivity {
stopButton.setOnClickListener(v -> stopFTPServer()); stopButton.setOnClickListener(v -> stopFTPServer());
selectDirButton.setOnClickListener(v -> selectDirectory()); selectDirButton.setOnClickListener(v -> selectDirectory());
saveSettingsButton.setOnClickListener(v -> saveSettings()); saveSettingsButton.setOnClickListener(v -> saveSettings());
manageUsersButton.setOnClickListener(v -> openUserManagement());
} }
private void selectDirectory() { private void selectDirectory() {
@@ -140,7 +155,45 @@ public class MainActivity extends AppCompatActivity {
return; return;
} }
// Validate data port range
String minPortStr = minDataPortEditText.getText().toString().trim();
String maxPortStr = maxDataPortEditText.getText().toString().trim();
int minDataPort = 0;
int maxDataPort = 0;
if (!minPortStr.isEmpty() || !maxPortStr.isEmpty()) {
if (minPortStr.isEmpty() || maxPortStr.isEmpty()) {
Toast.makeText(this, "Please enter both min and max data ports or leave both empty", Toast.LENGTH_SHORT).show();
return;
}
try {
minDataPort = Integer.parseInt(minPortStr);
maxDataPort = Integer.parseInt(maxPortStr);
if (minDataPort < 1024 || minDataPort > 65535 || maxDataPort < 1024 || maxDataPort > 65535) {
Toast.makeText(this, "Data ports must be between 1024 and 65535", Toast.LENGTH_SHORT).show();
return;
}
if (minDataPort >= maxDataPort) {
Toast.makeText(this, "Min data port must be less than max data port", Toast.LENGTH_SHORT).show();
return;
}
if (maxDataPort - minDataPort < 10) {
Toast.makeText(this, "Data port range should be at least 10 ports", Toast.LENGTH_SHORT).show();
return;
}
} catch (NumberFormatException e) {
Toast.makeText(this, "Invalid data port number", Toast.LENGTH_SHORT).show();
return;
}
}
config.setPort(port); config.setPort(port);
config.setDataPortRange(minDataPort, maxDataPort);
portTextView.setText("Port: " + port); portTextView.setText("Port: " + port);
Toast.makeText(this, "Settings saved", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Settings saved", Toast.LENGTH_SHORT).show();
@@ -194,6 +247,8 @@ public class MainActivity extends AppCompatActivity {
serviceIntent.setAction(FTPService.ACTION_START); serviceIntent.setAction(FTPService.ACTION_START);
serviceIntent.putExtra("port", config.getPort()); serviceIntent.putExtra("port", config.getPort());
serviceIntent.putExtra("rootDirUri", rootDirUri); serviceIntent.putExtra("rootDirUri", rootDirUri);
serviceIntent.putExtra("minDataPort", config.getMinDataPort());
serviceIntent.putExtra("maxDataPort", config.getMaxDataPort());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(serviceIntent); startForegroundService(serviceIntent);
@@ -239,4 +294,40 @@ public class MainActivity extends AppCompatActivity {
} }
} }
} }
/**
* Check if FTPService is currently running in the background
*/
private boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
if (manager != null) {
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (FTPService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
}
return false;
}
@Override
protected void onResume() {
super.onResume();
// Sync UI with actual service state when activity resumes
isServerRunning = isServiceRunning();
updateUI();
}
private void openUserManagement() {
Intent intent = new Intent(this, UserManagementActivity.class);
startActivity(intent);
}
private void initializeDefaultUser() {
FTPUserManager userManager = FTPUserManager.getInstance(this);
if (userManager.getAllUsers().isEmpty()) {
userManager.addUser("admin", "admin");
Toast.makeText(this, "Default user created: admin/admin\nPlease change the password in User Management", Toast.LENGTH_LONG).show();
}
}
} }

View File

@@ -0,0 +1,252 @@
package be.gyu.android.server.ftp;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
public class UserManagementActivity extends AppCompatActivity {
private FTPUserManager userManager;
private ListView userListView;
private UserListAdapter userAdapter;
private List<FTPUser> userList;
private TextView emptyView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_management);
userManager = FTPUserManager.getInstance(this);
initViews();
setupListeners();
refreshUserList();
}
private void initViews() {
userListView = findViewById(R.id.userListView);
emptyView = findViewById(R.id.emptyView);
Button addUserButton = findViewById(R.id.addUserButton);
userList = new ArrayList<>();
userAdapter = new UserListAdapter();
userListView.setAdapter(userAdapter);
userListView.setEmptyView(emptyView);
}
private void setupListeners() {
findViewById(R.id.addUserButton).setOnClickListener(v -> showAddUserDialog());
}
private void showAddUserDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_add_user, null);
builder.setView(dialogView);
TextView dialogTitle = dialogView.findViewById(R.id.dialogTitle);
EditText usernameEditText = dialogView.findViewById(R.id.usernameEditText);
EditText passwordEditText = dialogView.findViewById(R.id.passwordEditText);
EditText confirmPasswordEditText = dialogView.findViewById(R.id.confirmPasswordEditText);
TextView errorTextView = dialogView.findViewById(R.id.errorTextView);
Button saveButton = dialogView.findViewById(R.id.saveButton);
Button cancelButton = dialogView.findViewById(R.id.cancelButton);
dialogTitle.setText("Add User");
AlertDialog dialog = builder.create();
saveButton.setOnClickListener(v -> {
String username = usernameEditText.getText().toString().trim();
String password = passwordEditText.getText().toString();
String confirmPassword = confirmPasswordEditText.getText().toString();
// Validate username
if (username.isEmpty()) {
errorTextView.setText("Username is required");
errorTextView.setVisibility(View.VISIBLE);
return;
}
if (!userManager.isValidUsername(username)) {
errorTextView.setText("Username must be 3-20 characters, alphanumeric + underscore");
errorTextView.setVisibility(View.VISIBLE);
return;
}
if (userManager.userExists(username)) {
errorTextView.setText("Username already exists");
errorTextView.setVisibility(View.VISIBLE);
return;
}
// Validate password
if (password.isEmpty()) {
errorTextView.setText("Password is required");
errorTextView.setVisibility(View.VISIBLE);
return;
}
if (!userManager.isValidPassword(password)) {
errorTextView.setText("Password must be at least 4 characters");
errorTextView.setVisibility(View.VISIBLE);
return;
}
if (!password.equals(confirmPassword)) {
errorTextView.setText("Passwords do not match");
errorTextView.setVisibility(View.VISIBLE);
return;
}
// Add user
if (userManager.addUser(username, password)) {
Toast.makeText(this, "User added successfully", Toast.LENGTH_SHORT).show();
refreshUserList();
dialog.dismiss();
} else {
errorTextView.setText("Failed to add user");
errorTextView.setVisibility(View.VISIBLE);
}
});
cancelButton.setOnClickListener(v -> dialog.dismiss());
dialog.show();
}
private void showEditUserDialog(FTPUser user) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_add_user, null);
builder.setView(dialogView);
TextView dialogTitle = dialogView.findViewById(R.id.dialogTitle);
EditText usernameEditText = dialogView.findViewById(R.id.usernameEditText);
EditText passwordEditText = dialogView.findViewById(R.id.passwordEditText);
EditText confirmPasswordEditText = dialogView.findViewById(R.id.confirmPasswordEditText);
TextView errorTextView = dialogView.findViewById(R.id.errorTextView);
Button saveButton = dialogView.findViewById(R.id.saveButton);
Button cancelButton = dialogView.findViewById(R.id.cancelButton);
dialogTitle.setText("Edit User");
usernameEditText.setText(user.getUsername());
usernameEditText.setEnabled(false);
AlertDialog dialog = builder.create();
saveButton.setOnClickListener(v -> {
String password = passwordEditText.getText().toString();
String confirmPassword = confirmPasswordEditText.getText().toString();
// Validate password
if (password.isEmpty()) {
errorTextView.setText("Password is required");
errorTextView.setVisibility(View.VISIBLE);
return;
}
if (!userManager.isValidPassword(password)) {
errorTextView.setText("Password must be at least 4 characters");
errorTextView.setVisibility(View.VISIBLE);
return;
}
if (!password.equals(confirmPassword)) {
errorTextView.setText("Passwords do not match");
errorTextView.setVisibility(View.VISIBLE);
return;
}
// Update user
if (userManager.updateUser(user.getUsername(), password)) {
Toast.makeText(this, "User updated successfully", Toast.LENGTH_SHORT).show();
refreshUserList();
dialog.dismiss();
} else {
errorTextView.setText("Failed to update user");
errorTextView.setVisibility(View.VISIBLE);
}
});
cancelButton.setOnClickListener(v -> dialog.dismiss());
dialog.show();
}
private void showDeleteConfirmation(FTPUser user) {
// Check if this is the last user
if (userList.size() <= 1) {
Toast.makeText(this, "Cannot delete the last user", Toast.LENGTH_LONG).show();
return;
}
new AlertDialog.Builder(this)
.setTitle("Delete User")
.setMessage("Are you sure you want to delete user '" + user.getUsername() + "'?")
.setPositiveButton("Delete", (dialog, which) -> {
if (userManager.deleteUser(user.getUsername())) {
Toast.makeText(this, "User deleted successfully", Toast.LENGTH_SHORT).show();
refreshUserList();
} else {
Toast.makeText(this, "Failed to delete user", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel", null)
.show();
}
private void refreshUserList() {
userList.clear();
userList.addAll(userManager.getAllUsers());
userAdapter.notifyDataSetChanged();
}
private class UserListAdapter extends BaseAdapter {
@Override
public int getCount() {
return userList.size();
}
@Override
public Object getItem(int position) {
return userList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(UserManagementActivity.this)
.inflate(R.layout.item_user, parent, false);
}
FTPUser user = userList.get(position);
TextView usernameView = convertView.findViewById(R.id.usernameTextView);
Button editButton = convertView.findViewById(R.id.editButton);
Button deleteButton = convertView.findViewById(R.id.deleteButton);
usernameView.setText(user.getUsername());
editButton.setOnClickListener(v -> showEditUserDialog(user));
deleteButton.setOnClickListener(v -> showDeleteConfirmation(user));
return convertView;
}
}
}

View File

@@ -68,13 +68,24 @@
app:layout_constraintTop_toBottomOf="@id/startButton" app:layout_constraintTop_toBottomOf="@id/startButton"
android:layout_marginTop="16dp" /> android:layout_marginTop="16dp" />
<Button
android:id="@+id/manageUsersButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Manage Users"
android:minWidth="150dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/stopButton"
android:layout_marginTop="16dp" />
<View <View
android:id="@+id/divider" android:id="@+id/divider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:background="#CCCCCC" android:background="#CCCCCC"
android:layout_marginTop="32dp" android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="@id/stopButton" app:layout_constraintTop_toBottomOf="@id/manageUsersButton"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent" />
@@ -144,6 +155,62 @@
app:layout_constraintTop_toBottomOf="@id/rootDirPathTextView" app:layout_constraintTop_toBottomOf="@id/rootDirPathTextView"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/dataPortRangeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Port Range:"
android:textSize="16sp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/selectDirButton"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/minDataPortLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Min:"
android:textSize="14sp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@id/dataPortRangeLabel"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="@+id/minDataPortEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="50000"
android:layout_marginStart="16dp"
app:layout_constraintBaseline_toBaselineOf="@id/minDataPortLabel"
app:layout_constraintStart_toEndOf="@id/minDataPortLabel"
app:layout_constraintEnd_toStartOf="@id/maxDataPortLabel"
app:layout_constraintWidth_default="percent"
app:layout_constraintHorizontal_weight="1" />
<TextView
android:id="@+id/maxDataPortLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Max:"
android:textSize="14sp"
android:layout_marginStart="16dp"
app:layout_constraintBaseline_toBaselineOf="@id/minDataPortLabel"
app:layout_constraintStart_toEndOf="@id/minDataPortEditText" />
<EditText
android:id="@+id/maxDataPortEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="50100"
android:layout_marginStart="16dp"
app:layout_constraintBaseline_toBaselineOf="@id/minDataPortLabel"
app:layout_constraintStart_toEndOf="@id/maxDataPortLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintWidth_default="percent"
app:layout_constraintHorizontal_weight="1" />
<Button <Button
android:id="@+id/saveSettingsButton" android:id="@+id/saveSettingsButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -151,7 +218,7 @@
android:text="Save Settings" android:text="Save Settings"
android:minWidth="150dp" android:minWidth="150dp"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/selectDirButton" app:layout_constraintTop_toBottomOf="@id/minDataPortLabel"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent" />

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".UserManagementActivity">
<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Management"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp" />
<ListView
android:id="@+id/userListView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="16dp"
app:layout_constraintTop_toBottomOf="@id/titleTextView"
app:layout_constraintBottom_toTopOf="@id/addUserButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/emptyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No users. Add your first user."
android:textSize="16sp"
android:textColor="#999999"
android:visibility="gone"
app:layout_constraintTop_toTopOf="@id/userListView"
app:layout_constraintBottom_toBottomOf="@id/userListView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="@+id/addUserButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add User"
android:minWidth="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="16dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:id="@+id/dialogTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add User"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginBottom="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username:"
android:textSize="14sp"
android:layout_marginBottom="4dp" />
<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="3-20 characters, alphanumeric + underscore"
android:inputType="text"
android:layout_marginBottom="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
android:textSize="14sp"
android:layout_marginBottom="4dp" />
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Minimum 4 characters"
android:inputType="textPassword"
android:layout_marginBottom="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirm Password:"
android:textSize="14sp"
android:layout_marginBottom="4dp" />
<EditText
android:id="@+id/confirmPasswordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Re-enter password"
android:inputType="textPassword"
android:layout_marginBottom="8dp" />
<TextView
android:id="@+id/errorTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Error message"
android:textColor="#FF0000"
android:textSize="14sp"
android:visibility="gone"
android:layout_marginBottom="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="end">
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
style="?android:attr/borderlessButtonStyle"
android:layout_marginEnd="8dp" />
<Button
android:id="@+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save" />
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/usernameTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="16sp"
android:textStyle="bold"
android:text="Username" />
<Button
android:id="@+id/editButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit"
android:layout_marginStart="8dp"
style="?android:attr/borderlessButtonStyle" />
<Button
android:id="@+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:layout_marginStart="8dp"
style="?android:attr/borderlessButtonStyle" />
</LinearLayout>